Ejemplo n.º 1
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _context.Set <User>().FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    string pas = PasswordEncrypt.EncryptStringAes(model.Password, _config.Value.Salt);


                    _context.Set <User>().Add(new User
                    {
                        Email       = model.Email,
                        Password    = pas,
                        FirstName   = model.FirstName,
                        MiddleName  = model.MiddleName,
                        LastName    = model.LastName,
                        MobilePhone = model.MobilePhone,
                        Created     = DateTime.UtcNow
                    });
                    await _context.SaveChangesAsync();

                    await Authenticate(model.Email);

                    return(RedirectToAction("Index", "Home"));
                }

                ModelState.AddModelError("", "Некорректные логин и(или) пароль");
            }
            return(View(model));
        }