示例#1
0
        public IActionResult Register(RegisterModel model)
        {
            if (model.Password != model.ConfirmPassword ||
                !this.IsValidModel(model))
            {
                if (!ItemValidator.IsValidEmail(model.Email))
                {
                    this.ShowError(EmailIsNotValid);
                    return(this.View());
                }
                if (!ItemValidator.IsValidPassword(model.Password))
                {
                    this.ShowError(PasswordIsNotValid);
                    return(this.View());
                }
                if (!ItemValidator.IsValidName(model.FullName))
                {
                    this.ShowError(FullNameNotValid);
                    return(this.View());
                }
                if (model.Password != model.ConfirmPassword)
                {
                    this.ShowError(PasswordsDontMatch);
                    return(this.View());
                }

                this.ShowError(RegisterError);
                return(this.View());
            }

            var result = this.users.Create(
                model.Email,
                model.Password,
                model.FullName);

            if (result)
            {
                return(this.RedirectToLogin());
            }
            else
            {
                this.ShowError(EmailExistsError);
                return(this.View());
            }
        }