Exemple #1
0
        public ActionResult Register(RegisterViewModel register)
        {
            ActionResult result = null;

            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception();
                }

                User user = null;
                try
                {
                    user = _dal.GetUser(register.Username);
                }
                catch
                {
                }

                if (user != null)
                {
                    ModelState.AddModelError("invalid-user", "The username is already taken.");
                    throw new Exception();
                }

                PasswordHelper passHelper = new PasswordHelper(register.Password);
                User           newUser    = new User()
                {
                    FirstName = register.FirstName,
                    LastName  = register.LastName,
                    Email     = register.Email,
                    Username  = register.Username,
                    Salt      = passHelper.Salt,
                    Hash      = passHelper.Hash
                };

                newUser.Id = _dal.AddUser(newUser);
                LogUserIn(newUser);

                result = RedirectToAction("Index", "WorkoutManager");
            }
            catch (Exception)
            {
                result = View("Register");
            }

            return(result);
        }