func signinWithUserName(reqBody userReqPostBody) (*model.UserToken, *ae.Error) { user := model.User{} user.Email = reqBody.Email err := user.GetUserByEmail() if err == sql.ErrNoRows { return nil, ae.InvalidUserNamePassword("") } if err != nil { return nil, ae.DB("", err) } salt, err := user.GetPasswordSalt() if err != nil { return nil, ae.DB("", err) } user.Password = reqBody.Password user.HashPassword(salt) exists, err := user.IsValidUser() if err != nil || !exists { return nil, ae.InvalidUserNamePassword("") } userToken := model.UserToken{} userToken.UserID = user.UserID err = userToken.Add() if err != nil { return nil, ae.DB("", err) } return &userToken, nil }
func signinWithGoogle(reqBody userReqPostBody) (*model.UserToken, *ae.Error) { person, token, err := model.GetGooglUserDetails(reqBody.GoogleKey) if err != nil { return nil, ae.DB("", err) } user := model.User{Email: person.Emails[0].Value} if err = user.GetUserByEmail(); err != nil { if err == sql.ErrNoRows { user.Verified = true user.ProfilePicURL = person.Image.Url if err1 := user.Save(); err1 != nil { return nil, ae.DB("", err1) } } else { return nil, ae.DB("", err) } } gToken := model.GoogleToken{UserID: user.UserID} gToken.Token = *token if err := gToken.Replace(); err != nil { return nil, ae.DB("", err) } userToken := model.UserToken{} userToken.UserID = user.UserID err = userToken.Add() if err != nil { return nil, ae.DB("", err) } return &userToken, nil }