mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 08:10:28 +00:00
do register
This commit is contained in:
parent
415452dd89
commit
6ed73d34d9
1 changed files with 18 additions and 9 deletions
|
@ -109,19 +109,23 @@ func (ctrl *V1Controller) HandleSsoHeaderLogin() errchain.HandlerFunc {
|
|||
return validate.NewRequestError(errors.New("authentication failed. not SSO header found or empty"), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
usr, err := ctrl.repo.Users.GetOneEmail(r.Context(), email)
|
||||
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
|
||||
newToken, err := ctrl.svc.User.LoginWithoutPassword(r.Context(), strings.ToLower(email), false)
|
||||
// check if a user matching provided email is existing already
|
||||
_, err := ctrl.repo.Users.GetOneEmail(r.Context(), email)
|
||||
|
||||
if err != nil {
|
||||
// user not found -> create it
|
||||
var username = r.Header.Get("Remote-Name")
|
||||
var groups = r.Header.Get("Remote-Groups")
|
||||
|
||||
var groupArr = strings.Split(groups, ",")
|
||||
|
||||
groupTok := ""
|
||||
if len(groupArr) > 0 {
|
||||
groupTok = groupArr[0]
|
||||
}
|
||||
|
||||
regData := services.UserRegistration {
|
||||
GroupToken: "adf",
|
||||
GroupToken: groupTok,
|
||||
Name : username,
|
||||
Email : email,
|
||||
Password : "",
|
||||
|
@ -132,10 +136,15 @@ func (ctrl *V1Controller) HandleSsoHeaderLogin() errchain.HandlerFunc {
|
|||
log.Err(err).Msg("failed to register user from SSO HTTP headers")
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// login as user with provided password
|
||||
newToken, err := ctrl.svc.User.LoginWithoutPassword(r.Context(), strings.ToLower(email))
|
||||
|
||||
if err != nil {
|
||||
return validate.NewRequestError(errors.New("authentication failed"), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
||||
return server.JSON(w, http.StatusOK, TokenResponse{
|
||||
Token: "Bearer " + newToken.Raw,
|
||||
ExpiresAt: newToken.ExpiresAt,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue