add createMethod #1
|
@ -2,7 +2,6 @@ package usermngmt
|
||||||
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Selly-Modules/logger"
|
"github.com/Selly-Modules/logger"
|
||||||
|
@ -15,7 +14,7 @@ type CreateOptions struct {
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
|||||||
Name string
|
Name string
|
||||||
Phone string
|
Phone string
|
||||||
Email string
|
Email string
|
||||||
HashedPassword string
|
Password string
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
Status string
|
Status string
|
||||||
RoleID primitive.ObjectID
|
RoleID primitive.ObjectID
|
||||||
Other string
|
Other string
|
||||||
|
@ -29,7 +28,7 @@ func (s Service) Create(payload CreateOptions) error {
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Validate payload
|
// Validate payload
|
||||||
err := payload.validate()
|
err := payload.validate(ctx)
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -40,16 +39,6 @@ func (s Service) Create(payload CreateOptions) error {
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find roleID exists or not
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
if !s.isRoleIDAlreadyExisted(ctx, userData.RoleID) {
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
return errors.New("roleID does not exist")
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
}
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
// Find phone number,email exists or not
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
if s.isPhoneNumberOrEmailAlreadyExisted(ctx, userData.Phone, userData.Email) {
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
return errors.New("phone number or email already existed")
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
}
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
// Create device
|
// Create device
|
||||||
_, err = col.InsertOne(ctx, userData)
|
_, err = col.InsertOne(ctx, userData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -70,7 +59,7 @@ func (payload CreateOptions) newUser() (result User, err error) {
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
|||||||
Name: payload.Name,
|
Name: payload.Name,
|
||||||
Phone: payload.Phone,
|
Phone: payload.Phone,
|
||||||
Email: payload.Email,
|
Email: payload.Email,
|
||||||
HashedPassword: payload.HashedPassword,
|
HashedPassword: hashPassword(payload.Password),
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
|
|||||||
Status: payload.Status,
|
Status: payload.Status,
|
||||||
RoleID: payload.RoleID,
|
RoleID: payload.RoleID,
|
||||||
Other: payload.Other,
|
Other: payload.Other,
|
||||||
|
|
||||||
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() boolean thì:
trên sửa lại boolean thì:
- check existed dùng prefix `is`
- check có value, field nào đó dùng prefix `has`
trên sửa lại `isNameOrPhoneExisted`
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() have name or phone existed -> phone number or email already existed have name or phone existed -> phone number or email already existed
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() thiếu check roleId trong db thiếu check roleId trong db
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() isRoleIDAlreadyExisted -> isRoleIDExisted isRoleIDAlreadyExisted -> isRoleIDExisted
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() roleID does not exist -> role id does not exist lỗi là ngữ cảnh cho user đọc, nên viết clear tí roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() func này với func isRoleIDExisted nên đưa vô func func này với func isRoleIDExisted nên đưa vô func `payload.validate()`, gom tất cả validate trước khi xử lý về 1 chỗ
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() bỏ dấu space sau Create bỏ dấu space sau Create
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() password do module này hash, xem link này: password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() nên là note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được nên là `string`, nếu client không dùng mongodb thì phải cài thêm thư viện
note: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
![]() done done
![]() done done
![]() done done
![]() done done
|
|
@ -6,4 +6,6 @@ const (
|
||||||
tableRole = "roles"
|
tableRole = "roles"
|
||||||
|
|
||||||
timezoneHCM = "Asia/Ho_Chi_Minh"
|
timezoneHCM = "Asia/Ho_Chi_Minh"
|
||||||
|
|
||||||
|
passwordHashingCost = 14
|
||||||
)
|
)
|
||||||
|
|
28
db.go
|
@ -12,18 +12,23 @@ import (
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() done done
|
|||||||
|
|
||||||
// getUserCollection ...
|
// getUserCollection ...
|
||||||
func (s Service) getUserCollection() *mongo.Collection {
|
func (s Service) getUserCollection() *mongo.Collection {
|
||||||
|
if s.TablePrefix != "" {
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
return s.DB.Collection(fmt.Sprintf("%s-%s", s.TablePrefix, tableUser))
|
return s.DB.Collection(fmt.Sprintf("%s-%s", s.TablePrefix, tableUser))
|
||||||
}
|
}
|
||||||
|
return s.DB.Collection(tableUser)
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
|
}
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
|
|
||||||
// getRoleCollection ...
|
// getRoleCollection ...
|
||||||
func (s Service) getRoleCollection() *mongo.Collection {
|
func (s Service) getRoleCollection() *mongo.Collection {
|
||||||
return s.DB.Collection(fmt.Sprintf("%s-%s", s.TablePrefix, tableRole))
|
if s.TablePrefix != "" {
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
|
s.DB.Collection(fmt.Sprintf("%s-%s", s.TablePrefix, tableRole))
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
|
}
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
|
return s.DB.Collection(tableRole)
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) isPhoneNumberOrEmailAlreadyExisted(ctx context.Context, phone, email string) bool {
|
func (s Service) isPhoneNumberOrEmailExisted(ctx context.Context, phone, email string) bool {
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
var (
|
var (
|
||||||
col = s.getUserCollection()
|
col = s.getUserCollection()
|
||||||
user = User{}
|
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Find
|
// Find
|
||||||
|
@ -37,32 +42,33 @@ func (s Service) isPhoneNumberOrEmailAlreadyExisted(ctx context.Context, phone,
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() done done
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := col.FindOne(ctx, cond).Decode(&user); err != nil {
|
total, err := col.CountDocuments(ctx, cond)
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
logger.Error("usermngmt - findByCondition", logger.LogData{
|
if err != nil {
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
|
logger.Error("usermngmt - countUserByCondition", logger.LogData{
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
"condition": cond,
|
"condition": cond,
|
||||||
"err": err.Error(),
|
"err": err.Error(),
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return !user.ID.IsZero()
|
return total != 0
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) isRoleIDAlreadyExisted(ctx context.Context, roleID primitive.ObjectID) bool {
|
func (s Service) isRoleIDExisted(ctx context.Context, roleID primitive.ObjectID) bool {
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
var (
|
var (
|
||||||
col = s.getRoleCollection()
|
col = s.getRoleCollection()
|
||||||
role = Role{}
|
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Find
|
// Find
|
||||||
cond := bson.M{
|
cond := bson.M{
|
||||||
"_id": roleID,
|
"_id": roleID,
|
||||||
}
|
}
|
||||||
if err := col.FindOne(ctx, cond).Decode(&role); err != nil {
|
total, err := col.CountDocuments(ctx, cond)
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
logger.Error("usermngmt - findRoleByCondition", logger.LogData{
|
if err != nil {
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
|
logger.Error("usermngmt - countRoleByCondition", logger.LogData{
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
"condition": cond,
|
"condition": cond,
|
||||||
"err": err.Error(),
|
"err": err.Error(),
|
||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return !role.ID.IsZero()
|
return total != 0
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
|
|||||||
}
|
}
|
||||||
|
|
||||||
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() isPhoneNumberOrPhoneExisted isPhoneNumberOrPhoneExisted
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() chỗ này count là được chớ cần gì find chỗ này count là được chớ cần gì find
![]() count luôn count luôn
![]() count luôn count luôn
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() done done
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() set default rồi, bỏ cái này đi set default rồi, bỏ cái này đi
![]() done done
![]() done done
|
12
helper.go
|
@ -1 +1,13 @@
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
![]() done done
|
|||||||
package usermngmt
|
package usermngmt
|
||||||
|
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
import "golang.org/x/crypto/bcrypt"
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
func hashPassword(password string) string {
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
bytes, _ := bcrypt.GenerateFromPassword([]byte(password), passwordHashingCost)
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
return string(bytes)
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
}
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
func checkPasswordHash(password, hash string) bool {
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
return err == nil
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
}
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
|
|||||||
|
|
||||||
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi mấy method này nên tạo 1 file db.go để đưa vào, bên hàm export chỉ cần call vào thôi
xử lý db gom về 1 chỗ đúng hơn
![]() done done
![]() done done
|
4
model.go
|
@ -12,9 +12,9 @@ type User struct {
|
||||||
![]() HashedPassword HashedPassword
![]() HashedPassword HashedPassword
![]() done done
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]()
`bson:"roleId"`
![]() done done
![]() done done
![]() done done
![]() done done
|
|||||||
Name string `bson:"name" json:"name"`
|
Name string `bson:"name" json:"name"`
|
||||||
Phone string `bson:"phone" json:"phone"` // unique
|
Phone string `bson:"phone" json:"phone"` // unique
|
||||||
Email string `bson:"email" json:"email"` // unique
|
Email string `bson:"email" json:"email"` // unique
|
||||||
HashedPassword string `bson:"hashedPassword" json:"hashedPassword"`
|
HashedPassword string `bson:"hashedPassword" json:"-"`
|
||||||
![]() HashedPassword HashedPassword
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]() done done
![]() done done
![]() HashedPassword HashedPassword
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]() done done
![]() done done
|
|||||||
Status string `bson:"status" json:"status"`
|
Status string `bson:"status" json:"status"`
|
||||||
RoleID primitive.ObjectID `bson:"roleID" json:"roleId"`
|
RoleID primitive.ObjectID `bson:"roleId" json:"roleId"`
|
||||||
![]() HashedPassword HashedPassword
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]() done done
![]() done done
![]() HashedPassword HashedPassword
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]() done done
![]() done done
|
|||||||
Other string `bson:"other" json:"other"`
|
Other string `bson:"other" json:"other"`
|
||||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
|
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
|
||||||
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
|
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
|
||||||
|
|
||||||
![]() HashedPassword HashedPassword
![]() HashedPassword HashedPassword
![]() done done
![]() done done
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]() password không trả về ở json, để password không trả về ở json, để `-`
![]()
`bson:"roleId"`
![]()
`bson:"roleId"`
![]() done done
![]() done done
![]() done done
![]() done done
|
|
@ -31,7 +31,7 @@ var s *Service
|
||||||
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() done done
![]() done done
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() done done
![]() done done
|
|||||||
|
|
||||||
// Init ...
|
// Init ...
|
||||||
func Init(config Config) (*Service, error) {
|
func Init(config Config) (*Service, error) {
|
||||||
if config.MongoDB.Host == "" || config.TablePrefix == "" {
|
if config.MongoDB.Host == "" {
|
||||||
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() done done
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() done done
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() done done
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() done done
|
|||||||
return nil, errors.New("please provide all necessary information for init user")
|
return nil, errors.New("please provide all necessary information for init user")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() TablePrefix không require, nếu không có thì để default là TablePrefix không require, nếu không có thì để default là `usermngmt`
![]() done done
![]() done done
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() chỗ này chưa thấy check default
bên func get collection không cần check gì nữa chỗ này chưa thấy check default
```go
if config.TablePrefix == "" {
config.TablePrefix = ... // set trong config, default `usermngmt `
}
```
bên func get collection không cần check gì nữa
![]() done done
![]() done done
|
21
validate.go
|
@ -1,12 +1,13 @@
|
||||||
![]() check plain password check plain password
![]() check plain password check plain password
![]() done done
![]() done done
|
|||||||
package usermngmt
|
package usermngmt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/Selly-Modules/logger"
|
"github.com/Selly-Modules/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (co CreateOptions) validate() error {
|
func (co CreateOptions) validate(ctx context.Context) error {
|
||||||
![]() check plain password check plain password
![]() done done
![]() check plain password check plain password
![]() done done
|
|||||||
// Name
|
// Name
|
||||||
if co.Name == "" {
|
if co.Name == "" {
|
||||||
logger.Error("usermngmt - Create: no Name data", logger.LogData{
|
logger.Error("usermngmt - Create: no Name data", logger.LogData{
|
||||||
|
@ -31,12 +32,12 @@ func (co CreateOptions) validate() error {
|
||||||
![]() check plain password check plain password
![]() check plain password check plain password
![]() done done
![]() done done
|
|||||||
return errors.New("no email data")
|
return errors.New("no email data")
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashedPassword
|
// Password
|
||||||
![]() check plain password check plain password
![]() done done
![]() check plain password check plain password
![]() done done
|
|||||||
if co.HashedPassword == "" {
|
if co.Password == "" {
|
||||||
![]() check plain password check plain password
![]() done done
![]() check plain password check plain password
![]() done done
|
|||||||
logger.Error("usermngmt - Create: no hashedPassword data", logger.LogData{
|
logger.Error("usermngmt - Create: no password data", logger.LogData{
|
||||||
![]() check plain password check plain password
![]() done done
![]() check plain password check plain password
![]() done done
|
|||||||
"payload": co,
|
"payload": co,
|
||||||
})
|
})
|
||||||
return errors.New("no hashedPassword data")
|
return errors.New("no password data")
|
||||||
![]() check plain password check plain password
![]() done done
![]() check plain password check plain password
![]() done done
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
|
@ -55,5 +56,15 @@ func (co CreateOptions) validate() error {
|
||||||
![]() check plain password check plain password
![]() check plain password check plain password
![]() done done
![]() done done
|
|||||||
return errors.New("invalid roleID data")
|
return errors.New("invalid roleID data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find roleID exists or not
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
|
if !s.isRoleIDExisted(ctx, co.RoleID) {
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
|
return errors.New("role id does not exist")
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
|
}
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
|
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
|
// Find phone number,email exists or not
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
|
if s.isPhoneNumberOrEmailExisted(ctx, co.Phone, co.Email) {
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
|
return errors.New("phone number or email already existed")
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
|
}
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
|
|
||||||
![]() check plain password check plain password
![]() done done
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
![]() check plain password check plain password
![]() check plain password check plain password
![]() done done
![]() done done
|
boolean thì:
is
has
trên sửa lại
isNameOrPhoneExisted
boolean thì:
is
has
trên sửa lại
isNameOrPhoneExisted
have name or phone existed -> phone number or email already existed
have name or phone existed -> phone number or email already existed
thiếu check roleId trong db
thiếu check roleId trong db
done
done
done
done
done
done
password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
password client truyền vào là plain text, module này mới convert qua hash, đặt là hashedPassword
isRoleIDAlreadyExisted -> isRoleIDExisted
isRoleIDAlreadyExisted -> isRoleIDExisted
roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
roleID does not exist -> role id does not exist
lỗi là ngữ cảnh cho user đọc, nên viết clear tí
func này với func isRoleIDExisted nên đưa vô func
payload.validate()
, gom tất cả validate trước khi xử lý về 1 chỗfunc này với func isRoleIDExisted nên đưa vô func
payload.validate()
, gom tất cả validate trước khi xử lý về 1 chỗbỏ dấu space sau Create
bỏ dấu space sau Create
password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
password do module này hash, xem link này:
https://gowebexamples.com/password-hashing/
done
done
done
done
done
done
done
done
done
done
done
done
đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
đoạn này move qua db.go luôn, phân tách ra để gọn hàm, và đúng file
nên là
string
, nếu client không dùng mongodb thì phải cài thêm thư việnnote: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
nên là
string
, nếu client không dùng mongodb thì phải cài thêm thư việnnote: xử lý làm sao chỉ dùng type của go và của module, client chỉ cần cài 1 module này là sử dụng được
done
done
done
done