mirror of
https://github.com/harness/drone.git
synced 2025-05-16 08:59:56 +08:00
Update struct attribute names and pass register logic from handler to controller
This commit is contained in:
parent
959fb7b462
commit
ee683aa2c8
@ -23,8 +23,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type LoginInput struct {
|
type LoginInput struct {
|
||||||
Username string `json:"username"`
|
LoginIdentifier string `json:"login_identifier"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -34,15 +34,15 @@ func (c *Controller) Login(ctx context.Context, session *auth.Session,
|
|||||||
in *LoginInput) (*types.TokenResponse, error) {
|
in *LoginInput) (*types.TokenResponse, error) {
|
||||||
// no auth check required, password is used for it.
|
// no auth check required, password is used for it.
|
||||||
|
|
||||||
user, err := findUserFromUID(ctx, c.principalStore, in.Username)
|
user, err := findUserFromUID(ctx, c.principalStore, in.LoginIdentifier)
|
||||||
if errors.Is(err, store.ErrResourceNotFound) {
|
if errors.Is(err, store.ErrResourceNotFound) {
|
||||||
user, err = findUserFromEmail(ctx, c.principalStore, in.Username)
|
user, err = findUserFromEmail(ctx, c.principalStore, in.LoginIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
// always return not found for security reasons.
|
// always return not found for security reasons.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Ctx(ctx).Debug().Err(err).
|
log.Ctx(ctx).Debug().Err(err).
|
||||||
Str("user_uid", in.Username).
|
Str("user_uid", in.LoginIdentifier).
|
||||||
Msgf("failed to retrieve user during login.")
|
Msgf("failed to retrieve user during login.")
|
||||||
return nil, usererror.ErrNotFound
|
return nil, usererror.ErrNotFound
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ import (
|
|||||||
|
|
||||||
type RegisterInput struct {
|
type RegisterInput struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
DisplayName string `json:"displayname"`
|
DisplayName string `json:"display_name"`
|
||||||
Username string `json:"username"`
|
UID string `json:"uid"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,10 +24,15 @@ type RegisterInput struct {
|
|||||||
* This differs from the Create method as it doesn't require auth, but has limited
|
* This differs from the Create method as it doesn't require auth, but has limited
|
||||||
* functionalities (unable to create admin user for example).
|
* functionalities (unable to create admin user for example).
|
||||||
*/
|
*/
|
||||||
func (c *Controller) Register(ctx context.Context, in *CreateInput) (*types.TokenResponse, error) {
|
func (c *Controller) Register(ctx context.Context, in *RegisterInput) (*types.TokenResponse, error) {
|
||||||
// TODO: allow to configure if open register is allowed.
|
// TODO: allow to configure if open register is allowed.
|
||||||
|
|
||||||
user, err := c.CreateNoAuth(ctx, in, false)
|
user, err := c.CreateNoAuth(ctx, &CreateInput{
|
||||||
|
UID: in.UID,
|
||||||
|
Email: in.Email,
|
||||||
|
DisplayName: in.DisplayName,
|
||||||
|
Password: in.Password,
|
||||||
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create user: %w", err)
|
return nil, fmt.Errorf("failed to create user: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,7 @@ func HandleRegister(userCtrl *user.Controller) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenResponse, err := userCtrl.Register(ctx, &user.CreateInput{
|
tokenResponse, err := userCtrl.Register(ctx, in)
|
||||||
UID: in.Username,
|
|
||||||
Email: in.Email,
|
|
||||||
DisplayName: in.DisplayName,
|
|
||||||
Password: in.Password,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.TranslatedUserError(w, err)
|
render.TranslatedUserError(w, err)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user