additionl logs for oauth user flow

This commit is contained in:
abhishek9686 2024-04-04 08:55:08 +05:30
parent 19a2784b7f
commit 61703038ae
3 changed files with 7 additions and 1 deletions

View file

@ -264,7 +264,7 @@ func addUser(email string) error {
// TODO: add ability to add users with preemptive permissions
newUser.IsAdmin = false
if err = logic.CreateUser(&newUser); err != nil {
logger.Log(1, "error creating user,", email, "; user not added")
logger.Log(1, "error creating user,", email, "; user not added", "error", err.Error())
} else {
logger.Log(0, "user created from ", email)
}

View file

@ -70,6 +70,7 @@ func handleGoogleCallback(w http.ResponseWriter, r *http.Request) {
}
user, err := logic.GetUser(content.Email)
if err != nil {
logger.Log(0, "error fetching user: ", err.Error())
handleOauthUserNotFound(w)
return
}

View file

@ -96,12 +96,14 @@ func CreateUser(user *models.User) error {
}
var err = ValidateUser(user)
if err != nil {
logger.Log(0, "failed to validate user", err.Error())
return err
}
// encrypt that password so we never see it again
hash, err := bcrypt.GenerateFromPassword([]byte(user.Password), 5)
if err != nil {
logger.Log(0, "error encrypting pass", err.Error())
return err
}
// set password to encrypted password
@ -109,6 +111,7 @@ func CreateUser(user *models.User) error {
tokenString, _ := CreateUserJWT(user.UserName, user.IsSuperAdmin, user.IsAdmin)
if tokenString == "" {
logger.Log(0, "failed to generate token", err.Error())
return err
}
@ -117,10 +120,12 @@ func CreateUser(user *models.User) error {
// connect db
data, err := json.Marshal(user)
if err != nil {
logger.Log(0, "failed to marshal", err.Error())
return err
}
err = database.Insert(user.UserName, string(data), database.USERS_TABLE_NAME)
if err != nil {
logger.Log(0, "failed to insert user", err.Error())
return err
}