public IActionResult Register(UserRegisteringModel model)
        {
            if (!this.IsValidModel(model))
            {
                SetValidatorErrors();
                return(this.View());
            }

            int?position = this.users.GetPosition(model.Position);

            if (position == null)
            {
                this.ShowError(Constants.InvalidPossitionMessage);
                return(this.View());
            }

            var userId = this.users.Create(model.Email, model.Password, position);

            if (userId == null)
            {
                ShowError(Constants.UnsuccessfullRegistrationMessage);
                return(this.View());
            }

            this.SignIn(model.Email, userId.Value);

            return(this.RedirectToHome());
        }
Beispiel #2
0
        public IActionResult Register(UserRegisteringModel model)
        {
            if (!this.IsValidModel(model))
            {
                return(this.View());
            }

            var user = new User()
            {
                Username     = model.Username,
                FullName     = model.FullName,
                Email        = model.Email,
                PasswordHash = PasswordUtilities.GetPasswordHash(model.Password)
            };

            using (this.Context)
            {
                user.Role = this.Context
                            .Roles
                            .Where(r => r.RoleName == Constants.UserRole)
                            .Select(r => r)
                            .FirstOrDefault();

                this.Context.Users.Add(user);
                this.Context.SaveChanges();
                this.SignIn(user.Username, user.Id, new List <string>()
                {
                    user.Role.RoleName
                });
            }

            return(this.RedirectToHome());
        }
Beispiel #3
0
        public IActionResult Register(UserRegisteringModel model)
        {
            if (!this.IsValidModel(model))
            {
                SetValidatorErrors();
                return(this.View());
            }

            var user = this.users.Create(model.Username, model.Password, model.Email);

            if (user == null)
            {
                ShowError("Unsuccessfull Registration!");
                return(this.View());
            }

            this.SignIn(user.Username, user.Id);

            return(this.RedirectToHome());
        }
        public IActionResult Register(UserRegisteringModel model)
        {
            if (!IsValidModel(model))
            {
                string errorMessage = $"{this.ParameterValidator.ModelErrors.Values.Select(v => v.First()).First()}";
                this.Model.Data["errors"] = string.Format(ErrorBox, errorMessage);
                return(this.View());
            }

            if (this.Context.Users.Any(u => u.Username == model.Username))
            {
                this.Model.Data["errors"] = string.Format(ErrorBox, "Username already taken!");
                return(this.View());
            }


            if (this.Context.Users.Any(u => u.Email == model.Email))
            {
                this.Model.Data["errors"] = string.Format(ErrorBox, "Email already taken!");
                return(this.View());
            }

            var user = new User()
            {
                Username     = model.Username,
                Email        = model.Email,
                PasswordHash = PasswordUtilities.GetPasswordHash(model.Password)
            };

            using (this.Context)
            {
                this.Context.Users.Add(user);
                this.Context.SaveChanges();
                this.SignIn(user.Username, user.Id);
            }

            return(this.RedirectToHome());
        }
Beispiel #5
0
        public IActionResult Register(UserRegisteringModel model)
        {
            if (!this.IsValidModel(model))
            {
                return(this.View());
            }

            var user = new User()
            {
                Username     = model.Username,
                Email        = model.Email,
                PasswordHash = PasswordUtilities.GetPasswordHash(model.Password)
            };

            using (this.Context)
            {
                this.Context.Users.Add(user);
                this.Context.SaveChanges();
                this.SignIn(user.Username, user.Id);
            }

            return(this.RedirectToHome());
        }