fix: register user on org (#1614)

* fix: user register

* fix: user register translation

* display suffix correctly

* Update auth_request.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
Fabi 2021-04-19 12:43:17 +02:00 committed by GitHub
parent edc0958e41
commit 2768ab4184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 20 deletions

View File

@ -52,7 +52,7 @@ func (f Gender) Valid() bool {
}
func (u *Human) IsValid() bool {
return u.Profile != nil && u.Profile.IsValid() && u.Email != nil && u.Email.IsValid() && u.Phone == nil || (u.Phone != nil && u.Phone.PhoneNumber != "" && u.Phone.IsValid())
return u.Username != "" && u.Profile != nil && u.Profile.IsValid() && u.Email != nil && u.Email.IsValid() && u.Phone == nil || (u.Phone != nil && u.Phone.PhoneNumber != "" && u.Phone.IsValid())
}
func (u *Human) CheckOrgIAMPolicy(policy *OrgIAMPolicy) error {

View File

@ -1,9 +1,10 @@
package handler
import (
"github.com/caos/zitadel/internal/domain"
"net/http"
"github.com/caos/zitadel/internal/domain"
"golang.org/x/text/language"
caos_errs "github.com/caos/zitadel/internal/errors"
@ -15,6 +16,7 @@ const (
type registerFormData struct {
Email string `schema:"email"`
Username string `schema:"username"`
Firstname string `schema:"firstname"`
Lastname string `schema:"lastname"`
Language string `schema:"language"`
@ -33,6 +35,7 @@ type registerData struct {
HasLowercase string
HasNumber string
HasSymbol string
ShowUsername bool
}
func (l *Login) handleRegister(w http.ResponseWriter, r *http.Request) {
@ -98,27 +101,43 @@ func (l *Login) renderRegister(w http.ResponseWriter, r *http.Request, authReque
baseData: l.getBaseData(r, authRequest, "Register", errType, errMessage),
registerFormData: *formData,
}
iam, _ := l.authRepo.GetIAM(r.Context())
if iam != nil {
policy, description, _ := l.getPasswordComplexityPolicy(r, iam.GlobalOrgID)
if policy != nil {
data.PasswordPolicyDescription = description
data.MinLength = policy.MinLength
if policy.HasUppercase {
data.HasUppercase = UpperCaseRegex
}
if policy.HasLowercase {
data.HasLowercase = LowerCaseRegex
}
if policy.HasSymbol {
data.HasSymbol = SymbolRegex
}
if policy.HasNumber {
data.HasNumber = NumberRegex
}
resourceOwner := authRequest.RequestedOrgID
if resourceOwner == "" {
iam, err := l.authRepo.GetIAM(r.Context())
if err != nil {
l.renderRegister(w, r, authRequest, formData, err)
return
}
resourceOwner = iam.GlobalOrgID
}
pwPolicy, description, _ := l.getPasswordComplexityPolicy(r, resourceOwner)
if pwPolicy != nil {
data.PasswordPolicyDescription = description
data.MinLength = pwPolicy.MinLength
if pwPolicy.HasUppercase {
data.HasUppercase = UpperCaseRegex
}
if pwPolicy.HasLowercase {
data.HasLowercase = LowerCaseRegex
}
if pwPolicy.HasSymbol {
data.HasSymbol = SymbolRegex
}
if pwPolicy.HasNumber {
data.HasNumber = NumberRegex
}
}
orgIAMPolicy, err := l.getOrgIamPolicy(r, resourceOwner)
if err != nil {
l.renderRegister(w, r, authRequest, formData, err)
return
}
data.ShowUsername = orgIAMPolicy.UserLoginMustBeDomain
funcs := map[string]interface{}{
"selectedLanguage": func(l string) bool {
if formData == nil {
@ -138,6 +157,7 @@ func (l *Login) renderRegister(w http.ResponseWriter, r *http.Request, authReque
func (d registerFormData) toHumanDomain() *domain.Human {
return &domain.Human{
Username: d.Username,
Profile: &domain.Profile{
FirstName: d.Firstname,
LastName: d.Lastname,

View File

@ -143,6 +143,7 @@ Registration:
Title: Registration
Description: Gib deine Benutzerangaben an. Die E-Mail Adresse wird als Benutzernamen verwendet.
Email: E-Mail
Username: Benutzername
Firstname: Vorname
Lastname: Nachname
Language: Sprache

View File

@ -143,6 +143,7 @@ Registration:
Title: Registration
Description: Enter your Userdata. Your email address will be used as loginname.
Email: E-Mail
Username: Username
Firstname: Firstname
Lastname: Lastname
Language: Language

View File

@ -32,6 +32,18 @@
<input class="lgn-input" type="text" id="email" name="email" autocomplete="email" value="{{ .Email }}" required>
</div>
{{if .ShowUsername}}
<div class="lgn-field double">
<label class="lgn-label" for="email">{{t "Registration.Username"}}</label>
<div class="lgn-suffix-wrapper">
<input class="lgn-input lgn-suffix-input" type="text" id="username" name="username" autocomplete="email" value="{{ .Email }}" required>
{{if .DisplayLoginNameSuffix}}
<span id="default-login-suffix" lgnsuffix class="loginname-suffix">@{{.PrimaryDomain}}</span>
{{end}}
</div>
</div>
{{end}}
<div class="double-col">
<div class="lgn-field">
<label class="lgn-label" for="languages">{{t "Registration.Language"}}</label>
@ -109,6 +121,7 @@
</div>
</form>
<script src="{{ resourceUrl "scripts/input_suffix_offset.js" }}"></script>
<script src="{{ resourceUrl "scripts/form_submit.js" }}"></script>
<script src="{{ resourceUrl "scripts/password_policy_check.js" }}"></script>
<script src="{{ resourceUrl "scripts/register_check.js" }}"></script>