예제 #1
0
        public ActionResult Register(RegisterViewModel register)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            UserDto user = new UserDto();

            user.Login = register.Login;
            user.Email = register.Email;
            user.Password = register.Password;

            foreach (var item in _userService.RegisterUser(user))
            {
                if (item == 0)
                {
                    FormsAuthentication.SetAuthCookie(user.Login, true);
                    return RedirectToAction("Index", "Home");
                }
                else if (item == 1)
                {
                    errors.Add("Login już istnieje");
                }
                else if (item == 2)
                {
                    errors.Add("Email już istnieje");
                }
                else if (item == 3)
                {
                    errors.Add("Hasło musi zawierać minimum 5 znaków, w tym jedną cyfrę.");
                }

            }

            Session["val"] = errors.ToArray<string>();

            return View();
        }
예제 #2
0
        public ActionResult RecoveryPass(RegisterViewModel user)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            UserDto userDto = new UserDto();
            userDto.Password = user.Password;
            userDto.Code = user.RecoveryCode;
            userDto.Email = user.Email;

            int result = _userService.RecoveryPass(userDto);

            if (result == 1)
            {
                errors.Clear();
                errors.Add("Hasło zostało zmienione.");
                Session["val"] = errors.ToArray<string>();
                return RedirectToAction("Login");
            }
            else if (result == 2)
            {
                errors.Clear();
                errors.Add("Niepoprawny kod.");
            }
            else if (result == 3)
            {
                errors.Clear();
                errors.Add("Kod stracił ważność.");
            }
            Session["val"] = errors.ToArray<string>();
            return RedirectToAction("RecoveryPassword");
        }