public async Task <IActionResult> FirstRegistration(RMSUser user) { if (user != null) { var _role = new RMSRole { Name = "SuperUser", CanManageRestaurants = true }; await _db.RMSRoles.AddAsync(_role); await _db.SaveChangesAsync(); var _user = new RMSUser() { Name = user.Name, Email = user.Email, Password = BCrypt.Net.BCrypt.HashPassword(user.Password), ConfirmPassword = BCrypt.Net.BCrypt.HashPassword(user.ConfirmPassword), RMSRoleId = _role.RMSRoleId }; await _db.RMSUsers.AddAsync(_user); await _db.SaveChangesAsync(); TempData["firstregistration"] = "You have successfully Created a RMS SUPER USER!!!"; TempData["notificationType"] = NotificationType.Success.ToString(); return(RedirectToAction("Login", "RMS_Admin")); } return(View(user)); }
public async Task <IActionResult> Login(RMSUser user) { var _admin = await _db.RMSUsers.FirstOrDefaultAsync(ru => ru.Email == user.Email); if (_admin != null) { var _password = BCrypt.Net.BCrypt.Verify(user.Password, _admin.Password); if (_password == true) { _session.SetString("rmsloggedinuser", JsonConvert.SerializeObject(_admin)); _session.SetInt32("rmsloggedinuserid", _admin.RMSUserId); return(RedirectToAction("Dashboard", "RMS_Admin")); } else { ViewData["mismatch"] = "Email and Password do not match"; } } return(View(user)); }