コード例 #1
0
        public async Task <IActionResult> Register(UserRegViewModel userReg)
        {
            if (ModelState.IsValid)
            {
                IdentityUser user = new IdentityUser()
                {
                    UserName    = userReg.UserName,
                    Email       = userReg.Email,
                    PhoneNumber = userReg.Phone
                };
                IdentityResult result = await _userManager.CreateAsync(user, userReg.Password);

                if (result.Succeeded)
                {
                    //TODO - SignIn user
                    return(RedirectToAction("Index", "Home"));
                }

                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError(item.Code, item.Description);
                }
            }
            return(View(userReg));
        }
コード例 #2
0
        public async Task <IActionResult> Register(UserRegViewModel userReg)
        {
            if (ModelState.IsValid)
            {
                AppUser newUsr = new AppUser()
                {
                    UserName    = userReg.UserName,
                    FirstName   = userReg.ForName,
                    LastName    = userReg.LastName,
                    BirthDate   = userReg.DayofBirth,
                    Email       = userReg.Email,
                    PhoneNumber = userReg.Phone
                };
                IdentityResult res = await _userManager.CreateAsync(newUsr, userReg.Password);

                if (res.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                foreach (var item in res.Errors)
                {
                    ModelState.AddModelError(item.Code, item.Description);
                }
            }
            return(View(userReg));
        }
コード例 #3
0
        public IActionResult Success()
        {
            if (HttpContext.Session.GetInt32(LOGGED_IN_ID) == null)
            {
                return(RedirectToAction("Index"));
            }
            UserRegViewModel NewUser = JsonConvert.DeserializeObject <UserRegViewModel>((string)TempData["user"]);

            ViewBag.User = NewUser;
            return(View());
        }
コード例 #4
0
 public void Add(UserRegViewModel NewUser)
 {
     using (IDbConnection dbConnection = Connection)
     {
         string query = "INSERT INTO users ";
         query += "(username, first_name, last_name, email, birthdate, password) ";
         query += $"VALUES('{NewUser.Username}', '{NewUser.FirstName}', '{NewUser.LastName}', '{NewUser.Email}', STR_TO_DATE('{NewUser.Birthdate}', '%m/%d/%Y %h:%i:%s %p'), '{NewUser.Password}')";
         dbConnection.Open();
         dbConnection.Execute(query);
     }
 }
コード例 #5
0
        public IActionResult UpdateSettings(UserRegViewModel model, int userId)
        {
            User upUser = _context.Users.Include(u => u.Reviews).SingleOrDefault(u => u.UserId == userId);

            if (ModelState.IsValid)
            {
                upUser.FirstName = model.FirstName;
                upUser.LastName  = model.LastName;
                upUser.Email     = model.Email;
                upUser.Password  = model.Password;
                upUser.ZipCode   = model.ZipCode;
                upUser.UpdatedAt = DateTime.Now;
                _context.Update(upUser);
                _context.SaveChanges();
                return(RedirectToAction("UserProfile"));
            }
            return(RedirectToAction("UserProfile"));
        }
コード例 #6
0
ファイル: AccountController.cs プロジェクト: cykevin/jl.web
        public ActionResult Reg(UserRegViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var existed = WebSecurity.UserExists(model.UserName);

                    var token = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email }, requireConfirmationToken: false);

                    Roles.AddUserToRole(model.UserName, JL.Core.Consts.Role_User);
                }

                return(RedirectToAction("Info"));
            }
            catch (Exception e)
            {
                logger.Error(JL.Utils.JsonHelper.ObjectToString(model), e);
                return(View());
            }
        }