예제 #1
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                List <UserModel> users     = Idao.GetUsers();
                List <string>    newErrors = new List <string>();
                bool             err       = false;
                foreach (UserModel user in users)
                {
                    if (user.Email == model.Email)
                    {
                        err = true;
                        newErrors.Add("User with this e-mail already exists! Choose annnother one!");
                    }
                    else if (user.Name == model.Username)
                    {
                        err = true;
                        newErrors.Add("User with this username already exists! Choose annnother one!");
                    }
                }

                if (err)
                {
                    model.errors = newErrors;
                    return(View(model));
                }
                else
                {
                    Idao.Register(model.Username, model.Email, model.Password);
                    await LoginAsync(model.Email, model.Password);

                    return(View("RegSuccess"));
                }
            }
            else
            {
                return(View());
            }
        }
예제 #2
0
 public InMemoryUserService()
 {
     _users = Idao.GetUsers();
 }