-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[be] Написать бекэнд для страницы регистрации #1
Conversation
нужны тесты |
api/signup.go
Outdated
} | ||
} | ||
|
||
func sanitizeParams(signupRequest signupApiRequest) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
думаю стоит переименовать на validate
api/signup.go
Outdated
var signupRequest signupApiRequest | ||
err := json.NewDecoder(r.Body).Decode(&signupRequest) | ||
|
||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
перенос строки после var,
убрать перенос после NewDecoder
db/db.go
Outdated
"errors" | ||
) | ||
|
||
var users = make(map[string]User) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше сделать отдельную структуру с sync.Mutex, так как при работе с мапой в горутинах -- неизбежная паника
api/signup.go
Outdated
return | ||
} | ||
|
||
err = db.CreateUser(signupRequest.Email, signupRequest.User) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужно хэширование пароля, используй Argon2
api/signup.go
Outdated
return ErrEmptyRequestParams | ||
} | ||
|
||
if len(signupRequest.Username) < 3 || len(signupRequest.Username) > 20 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minUsernameLen, maxUsernameLen (понимаете про что я)
api/signup.go
Outdated
return ErrWrongEmailFormat | ||
} | ||
|
||
if len(signupRequest.Password) < 5 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
api/types.go
Outdated
|
||
type signupApiRequest struct { | ||
Email string `json:"email"` | ||
db.User |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
явно назвать поле надо
cmd/main.go
Outdated
|
||
r.HandleFunc("/signup", api.SignupHandler).Methods("POST") | ||
http.Handle("/", r) | ||
_ = http.ListenAndServe("127.0.0.1:8080", nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
если роняете сервак, лучше напишите об этом сообщение в консоль
ebafbbb
to
a0dc886
Compare
fix: Изменены тесты для регистрации improve: Изменена логика функции writeJSON()
feat: Добавлена регистрация
P.S. Санитайзер на уровне - что в голову пришло, позже будет исправлен в соответствии с общими требованиями к санитайзингу в т.ч. на фронте