public async Task <IActionResult> AddStaff(AdminVM vm) { StaffUser user = new StaffUser { UserName = vm.NewStaff.Email }; IdentityResult result = await userManager.CreateAsync(user, vm.Password); if (result.Succeeded) { await userManager.AddToRoleAsync(user, vm.NewStaff.Role); } ; StaffProfile profile = new StaffProfile { FirstName = vm.NewStaff.FirstName, LastName = vm.NewStaff.LastName, Email = vm.NewStaff.Email, EmailNotifications = vm.NewStaff.EmailNotifications, User = user, Role = vm.NewStaff.Role }; staffRepo.AddStaff(profile); return(RedirectToAction("Staff")); }
private void ReceiveLoginMessage(StaffUser userAccount) { if (userAccount.isReceptionist()) { string firstname = userAccount.getFirstname(); ViewModelLocator.Cleanup(); CurrentToolbarViewModel = ReceptionistToolbarVM; CurrentViewModel = ReceptionistVM; MessengerInstance.Send <NotificationMessage>(new NotificationMessage(firstname)); // FROM: MainVM TO: ReceptionistToolbarVM ~ sends logged in users first name. } else if (userAccount.isDoctor()) { UserID = StaffDBConverter.GetAccountIDByUsername(userAccount.getUsername()); CurrentToolbarViewModel = DoctorToolbarVM; if (PatientDBConverter.DoctorIsInAppointment(UserID)) { CurrentViewModel = DoctorAppointmentVM; MessengerInstance.Send <int>(UserID); } else { CurrentViewModel = DoctorVM; MessengerInstance.Send <int>(UserID); } } }
protected override Guid GetUserId(HttpContext context) { if (context == null) { return(Guid.Empty); } StaffUser u = context.Items["Admin-User-Data"] as StaffUser; if (u != null) { return(u.Id); } Guid uid = Guid.Empty; //Cookie.Get<Guid>("CenterStaffUser"); string configedId = ConfigurationManager.AppSettings["SystemUserId"]; if (string.IsNullOrWhiteSpace(configedId) == false) { Guid.TryParse(configedId.Trim(), out uid); } if (uid == Guid.Empty) { throw new ApplicationException("没有配置web.config文件中的Key为SystemUserId的appSettings节点"); //return Guid.Empty; } u = Api <IStaffUserApi> .Instance.Get(uid); if (u == null) { throw new ApplicationException("web.config文件中的Key为SystemUserId的appSettings节点所配置的UserId:" + uid + ",找不到对应的StaffUser数据"); //Cookie.Remove("CenterStaffUser"); //return Guid.Empty; } context.Items["Admin-User-Data"] = u; return(u.Id); }
public ActionResult EditStaffUser(StaffUser model) { MembershipUser user = Membership.GetUser(model.UserName); user.IsApproved = model.ActiveAccount; Membership.UpdateUser(user); if (Roles.IsUserInRole(model.UserName, "Administrators") && !model.IsAdmin) { //if user was an admin but we delected admin Roles.RemoveUserFromRole(model.UserName, "Administrators"); } else if (!Roles.IsUserInRole(model.UserName, "Administrators") && model.IsAdmin) { Roles.AddUserToRole(model.UserName, "Administrators"); } //Membership.UpdateUser(user); if (Roles.IsUserInRole(model.UserName, "Staff") && !model.IsStaff) { Roles.RemoveUserFromRole(model.UserName, "Staff"); } else if (!Roles.IsUserInRole(model.UserName, "Staff") && model.IsStaff) { Roles.AddUserToRole(model.UserName, "Staff"); } Membership.UpdateUser(user); return(RedirectToAction("AdminIndex", "Admin")); }
public void CreateDeleteTicketPosts() { DepartmentCollection depts = TestSetup.KayakoApiService.Departments.GetDepartments(); StaffUserCollection staff = TestSetup.KayakoApiService.Staff.GetStaffUsers(); StaffUser randomStaffUser = staff[new Random().Next(staff.Count)]; TicketCollection tickets = TestSetup.KayakoApiService.Tickets.GetTickets(depts.Select(d => d.Id).ToArray()); Ticket randomTicket = tickets[new Random().Next(tickets.Count)]; string contents = "This will be the contents"; TicketNoteRequest request = new TicketNoteRequest() { TicketId = randomTicket.Id, Content = contents, StaffId = randomStaffUser.Id, ForStaffId = randomStaffUser.Id, NoteColor = NoteColor.Purple }; TicketNote createdNote = TestSetup.KayakoApiService.Tickets.AddTicketNote(request); Assert.IsNotNull(createdNote); Assert.AreEqual(createdNote.Content, contents); Assert.AreEqual(createdNote.ForStaffId, randomStaffUser.Id); //Assert.AreEqual(createdNote.CreatorStaffId, randomStaffUser.Id); Assert.AreEqual(createdNote.NoteColor, NoteColor.Purple); Assert.AreEqual(createdNote.TicketId, randomTicket.Id); bool success = TestSetup.KayakoApiService.Tickets.DeleteTicketNote(randomTicket.Id, createdNote.Id); Assert.IsTrue(success); }
protected override Guid GetUserId(HttpContext context) { if (context == null) { return(Guid.Empty); } StaffUser u = context.Items["Admin-User-Data"] as StaffUser; if (u != null) { return(u.Id); } Guid uid = Cookie.Get <Guid>("StaffUser"); if (uid == Guid.Empty) { return(Guid.Empty); } u = Api <IStaffUserApi> .Instance.Get(uid); if (u == null) { Cookie.Remove("StaffUser"); return(Guid.Empty); } context.Items["Admin-User-Data"] = u; return(u.Id); }
public void CreateDeleteTicketPosts() { DepartmentCollection depts = TestSetup.KayakoApiService.Departments.GetDepartments(); StaffUserCollection staff = TestSetup.KayakoApiService.Staff.GetStaffUsers(); StaffUser randomStaffUser = staff[new Random().Next(staff.Count)]; TicketCollection tickets = TestSetup.KayakoApiService.Tickets.GetTickets(depts.Select(d => d.Id).ToArray()); Ticket randomTicket = tickets[new Random().Next(tickets.Count)]; const string subject = "New Post Subject"; const string contents = "This will be the contents"; TicketPostRequest request = new TicketPostRequest() { TicketId = randomTicket.Id, Subject = subject, Contents = contents, StaffId = randomStaffUser.Id, IsPrivate = false }; TicketPost createdPost = TestSetup.KayakoApiService.Tickets.AddTicketPost(request); Assert.IsNotNull(createdPost); Assert.AreEqual(createdPost.StaffId, randomStaffUser.Id); //Assert.AreEqual(createdPost.Contents, String.Format("{0}\n{1}", contents, randomStaffUser.Signature)); //Subject? bool success = TestSetup.KayakoApiService.Tickets.DeleteTicketPost(randomTicket.Id, createdPost.Id); Assert.IsTrue(success); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new StaffUser { UserName = model.Email, Email = model.Email, PhoneNumber = model.Mobile, Fullname = model.Fullname, PasswordHash = model.Password }; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await signInManager.SignInAsync(user, isPersistent : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } //AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult DeleteStaffUser(string UserName) { StaffUser model = new StaffUser(); model.UserName = UserName; return(View(model)); }
public void CreateDeleteTicketAttachment() { DepartmentCollection depts = TestSetup.KayakoApiService.Departments.GetDepartments(); StaffUserCollection staff = TestSetup.KayakoApiService.Staff.GetStaffUsers(); StaffUser randomStaffUser = staff[new Random().Next(staff.Count)]; TicketCollection tickets = TestSetup.KayakoApiService.Tickets.GetTickets(depts.Select(d => d.Id).ToArray()); Ticket randomTicket = tickets[new Random().Next(tickets.Count)]; TicketPostCollection ticketPosts = TestSetup.KayakoApiService.Tickets.GetTicketPosts(randomTicket.Id); TicketPost randomPost = ticketPosts[new Random().Next(ticketPosts.Count)]; string contents = Convert.ToBase64String(Encoding.UTF8.GetBytes("This is the file contents")); TicketAttachmentRequest request = new TicketAttachmentRequest() { TicketId = randomTicket.Id, TicketPostId = randomPost.Id, FileName = "TheFilename.txt", Contents = contents }; TicketAttachment createdAttachment = TestSetup.KayakoApiService.Tickets.AddTicketAttachment(request); Assert.AreEqual(createdAttachment.TicketId, randomTicket.Id); Assert.AreEqual(createdAttachment.TicketPostId, randomPost.Id); Assert.AreEqual(createdAttachment.FileName, "TheFilename.txt"); //Assert.AreEqual(createdAttachment.Contents, contents); bool success = TestSetup.KayakoApiService.Tickets.DeleteTicketAttachment(randomTicket.Id, createdAttachment.Id); Assert.IsTrue(success); }
private StaffUser CheckUserLogin(string loginId, string password) { if (string.IsNullOrWhiteSpace(loginId) || string.IsNullOrWhiteSpace(password)) { throw new BizException("登录名或密码不能为空"); } loginId = loginId.Trim(); string sql = string.Format(@" SELECT TOP 1 a.* FROM [FlyBase].[dbo].[StaffUser] AS a WITH(NOLOCK) WHERE a.[LoginId]=@loginId" ); StaffUser au = null; string passwordDB = null; string passwordSaltDB = null; SqlHelper.ExecuteReaderFirst(reader => { au = SqlHelper.ConvertReaderToEntity <StaffUser>(reader); passwordDB = reader.Field <string>("Password"); passwordSaltDB = reader.Field <string>("PasswordSalt"); }, DbInstance.OnlyRead, sql, new { loginId }); if (au == null) { throw new BizException("登录名和密码不匹配"); } string pwd = this.GeneratePassword(password, passwordSaltDB); if (pwd != passwordDB) { pwd = this.GeneratePassword(password, passwordSaltDB, 2); if (pwd != passwordDB) { throw new BizException("登录名和密码不匹配"); } } if (au.Status == DataStatus.Deleted) { throw new BizException("此用户已经被删除,无法恢复,不能再登录"); } if (au.Status == DataStatus.Disabled) { throw new BizException("此用户已被禁用,不能再登录;需要系统管理员重新启用此账号后才能进行登录"); } if (HasPermission(au.Id, "Fly_Login") == false) { throw new BizException("账号\"{0}\"没有登陆当前系统的权限", loginId); } return(au); }
public void SetRoles(Guid userId, IEnumerable <Guid> roleIds) { StaffUser user = Api <IStaffUserApi> .Instance.Get(userId); if (user == null) { throw new ApplicationException("Id为" + userId + "的StaffUser数据不存在"); } if (user.Status == DataStatus.Deleted) { throw new BizException("此用户已经被删除,无法再修改其角色"); } StringBuilder sb = new StringBuilder(); if (roleIds != null && roleIds.Count() > 0) { foreach (Guid roleId in roleIds) { if (sb.Length > 0) { sb.Append(@" UNION ALL"); } sb.AppendFormat(@" SELECT '{0}' AS [UserId] ,'{1}' AS [RoleId]", userId, roleId); } } if (sb.Length > 0) { sb.Insert(0, @" INSERT INTO [FlyBase].[dbo].[StaffUserInRole] ( [UserId] ,[RoleId] )"); } // 先删除原来的 sb.Insert(0, string.Format(@" DELETE FROM [FlyBase].[dbo].[StaffUserInRole] WHERE [UserId]='{0}'" , userId)); int x = SqlHelper.ExecuteNonQuery(DbInstance.CanWrite, sb.ToString()); if (x > 0) { Cache.RemoveFromLocalCache("roles_" + userId); foreach (var roleId in roleIds) { Cache.RemoveFromLocalCache("users_" + roleId); } } }
public async Task <ActionResult> ConfirmEmail(StaffUser user, string code) { if (user == null || code == null) { return(View("Error")); } var result = await userManager.ConfirmEmailAsync(user, code); return(View(result.Succeeded ? "ConfirmEmail" : "Error")); }
public ActionResult EditStaffUser(string UserName) { MembershipUser user = Membership.GetUser(UserName); StaffUser model = new StaffUser(); model.UserName = user.UserName; model.LastLoginDate = user.LastLoginDate; model.ActiveAccount = user.IsApproved; model.IsAdmin = Roles.IsUserInRole(user.UserName, "Administrators"); model.IsStaff = Roles.IsUserInRole(user.UserName, "Staff"); return(View(model)); }
public bool UpdateStaffUser(StaffUser staffUser) { try { return(_staffUserManager.UpdateStaffUser(staffUser)); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(false); } }
public int AddStaffUser(StaffUser staffUser) { try { return(_staffUserManager.AddStaffUser(staffUser)); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
// GET: Admin public ActionResult AdminIndex() { MembershipUserCollection users = Membership.GetAllUsers(); List <StaffUser> su = new List <StaffUser>(); foreach (MembershipUser mu in users) { StaffUser user = new StaffUser(mu.UserName, mu.LastLoginDate, mu.IsApproved); user.IsAdmin = Roles.IsUserInRole(mu.UserName, "Administrators"); user.IsStaff = Roles.IsUserInRole(mu.UserName, "Staff"); su.Add(user); } return(View(su)); }
public void GetStaffUser() { StaffUserCollection staffUsers = TestSetup.KayakoApiService.Staff.GetStaffUsers(); Assert.IsNotNull(staffUsers, "No staff users were returned"); Assert.IsNotEmpty(staffUsers, "No staff users were returned"); StaffUser staffUserToGet = staffUsers[new Random().Next(staffUsers.Count)]; Trace.WriteLine("GetStaffUser using staff user id: " + staffUserToGet.Id); StaffUser staffUser = TestSetup.KayakoApiService.Staff.GetStaffUser(staffUserToGet.Id); CompareStaffUsers(staffUser, staffUserToGet); }
public static string GetCurrentUserDisplayName(this IContext context) { Guid uid = context.UserId; if (uid == Guid.Empty) { return(string.Empty); } StaffUser u = Api <IStaffUserApi> .Instance.Get(uid); if (u == null) { return(string.Empty); } return(u.DisplayName); }
public void AddTempPermissionSetting(Guid userId, string permissionKey, DateTime fromTime, DateTime toTime) { StaffUser user = Api <IStaffUserApi> .Instance.Get(userId); if (user == null) { throw new ApplicationException("Id为'" + userId + "'的系统用户不存在!"); } if (string.IsNullOrWhiteSpace(permissionKey)) { throw new BizException("临时权限的权限点不能为空!"); } if (fromTime >= toTime) { throw new BizException("临时权限的有效期开始时间必须小于结束时间!"); } string sql = @" UPDATE TOP (1) [FlyBase].[dbo].[StaffUserTempPermission] SET [FromTime]=@fromTime, [ToTime]=@toTime, [UpdatedOn]=GETDATE(), [UpdatedBy]=@operatorId WHERE [UserId]=@userId AND [PermissionKey]=@permissionKey IF @@ROWCOUNT<=0 BEGIN INSERT INTO [FlyBase].[dbo].[StaffUserTempPermission] ( [UserId], [PermissionKey], [FromTime], [ToTime], [UpdatedOn], [UpdatedBy] ) VALUES ( @userId, @permissionKey, @fromTime, @toTime, GETDATE(), @operatorId ) END"; int x = SqlHelper.ExecuteNonQuery(DbInstance.CanWrite, sql, new { userId, permissionKey, fromTime, toTime, operatorId = ContextManager.Current.UserId }); if (x > 0) { string key = "temp_permission_" + userId; Cache.RemoveFromLocalCache(key); } }
public void SignInValidation() { StaffUser staffUser = new StaffUser(Username, Password); if (staffUser.userExists()) { if (staffUser.verifyPassword()) { //check if account is Doctor OR Receptionist --> Otherwise trigger alert if (!(staffUser.isDoctor() || staffUser.isReceptionist())) { Alert("Account Not Authorised", "Your account credentials are not authorised to access" + " this system."); return; } string inputtedCode = Otp(); string otpToken = staffUser.getOTP(); var bytes = Base32Encoding.ToBytes(otpToken); var totp = new Totp(bytes); var totpCode = totp.ComputeTotp(); if (totpCode == inputtedCode) { //Returns user signed in to MainViewModel Messenger.Default.Send <StaffUser>(new StaffUser(staffUser.getUsername(), "")); } else { Alert("One-Time Password Incorrect", "The inputted code is incorrect. Please verify your TOTP and " + "retry. If issues persist, please contact the IT administrator or speak to a member of HR."); } } else { Alert("Password Incorrect", "Incorrect password. Please try again. If issues persist, please contact" + " the IT administrator or speak to a member of HR."); } } else { Alert("User Not Found", "The account could not be found. Please check your username & try again. If issues" + " persist, please contact the IT administrator or speak to a member of HR."); } }
public JsonResult AjaxDoUpdateUser(Guid adminUserId, string displayName, string password, string password2, string email, string mobile, string roles) { StaffUser adminUser = Api <IStaffUserApi> .Instance.Get(adminUserId); if (adminUser == null) { throw new BizException("ID为'{0}'的系统用户不存在!", adminUserId); } List <Guid> roleList = Utility.ConvertStringToGuidList(roles); if (string.IsNullOrWhiteSpace(password) == false) { if (string.IsNullOrWhiteSpace(password2)) { throw new BizException("确认密码不能为空!"); } if (password != password2) { throw new BizException("密码和确认密码不同!"); } } using (var tran = TransactionManager.Create()) { if (string.IsNullOrWhiteSpace(displayName) == false) { Api <IStaffUserApi> .Instance.Update(adminUserId, displayName, email, mobile); } if (string.IsNullOrWhiteSpace(password) == false) { Api <IStaffUserApi> .Instance.ChangePassword(adminUserId, password); } Api <IStaffUserApi> .Instance.SetRoles(adminUserId, roleList); tran.Complete(); } string url = LinkUrl("StaffUser/UserDetail", new { id = adminUserId }); return(Json(new { url = url })); }
public async Task <IActionResult> SendCode(RegisterViewModel mod, SendCodeViewModel model) { if (!ModelState.IsValid) { return(View()); } var user = new StaffUser { UserName = mod.Email, Email = mod.Email }; var res = await userManager.CreateAsync(user, mod.Password); // Generate the token and send it if (res.Succeeded) { return(RedirectToAction("VerifyCode", new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe })); } return(View("Error")); }
public IActionResult SendPasswordResetLink(int id) { StaffProfile profile = profileRepo.GetStaffProfileByID(id); StaffUser user = userManager. FindByNameAsync(profile.User.UserName).Result; if (user == null) { return(View("Index")); } var token = userManager. GeneratePasswordResetTokenAsync(user).Result; var resetLink = Url.Action("ResetPassword", "Auth", new { token = token }, protocol: HttpContext.Request.Scheme); var email = new MimeMessage(); email.From.Add(new MailboxAddress("KWFCI", "*****@*****.**")); email.Subject = "Password Reset"; email.Body = new TextPart("plain") { Text = "Click the link to reset your password " + resetLink }; email.To.Add(new MailboxAddress(user.UserName)); using (var client = new SmtpClient()) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect("smtp.gmail.com", 587, false); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate("kwfamilycheckin", "Fancy123!"); client.Send(email); client.Disconnect(true); } //TODO: Pop up Alert box saying the reset link has been sent to their email return(RedirectToAction("Index", profile)); }
public async Task <IActionResult> StaffDelete(int id) { StaffProfile profile = staffRepo.GetStaffProfileByID(id); if (profile != null) { StaffUser user = await userManager.FindByNameAsync(profile.Email); await userManager.DeleteAsync(user); staffRepo.DeleteStaff(profile); return(RedirectToAction("Staff")); } else { ModelState.AddModelError("", "Staff Not Found"); } return(RedirectToAction("Home")); }
public IActionResult ResetPassword(ResetPasswordVM vm) { if (vm.Password == vm.ConfirmPassword) { StaffUser user = userManager. FindByNameAsync(vm.UserName).Result; IdentityResult result = userManager.ResetPasswordAsync (user, vm.Token, vm.Password).Result; if (result.Succeeded) { return(View("Login")); } else { return(View("ResetPassword")); } } return(View("ResetPassword")); }
private void CompareStaffUsers(StaffUser one, StaffUser two) { Assert.AreEqual(one.Designation, two.Designation); Assert.AreEqual(one.Email, two.Email); Assert.AreEqual(one.EnableDst, two.EnableDst); Assert.AreEqual(one.FirstName, two.FirstName); Assert.AreEqual(one.FullName, two.FullName); Assert.AreEqual(one.Greeting, two.Greeting); Assert.AreEqual(one.GroupId, two.GroupId); Assert.AreEqual(one.Id, two.Id); Assert.AreEqual(one.IsEnabled, two.IsEnabled); Assert.AreEqual(one.LastName, two.LastName); Assert.AreEqual(one.MobileNumber, two.MobileNumber); //Can't test signature as it doesn't come back from the Api //Assert.AreEqual(one.Signature, two.Signature); Assert.AreEqual(one.TimeZone, two.TimeZone); Assert.AreEqual(one.UserName, two.UserName); AssertObjectXmlEqual <StaffUser>(one, two); }
public void CreateUpdateDeleteStaffUser() { StaffUser dummyStaffUser = TestData; StaffUserRequest req = StaffUserRequest.FromResponseData(dummyStaffUser); req.Password = "******"; StaffUser createdStaffUser = TestSetup.KayakoApiService.Staff.CreateStaffUser(req); Assert.IsNotNull(createdStaffUser); dummyStaffUser.Id = createdStaffUser.Id; CompareStaffUsers(dummyStaffUser, createdStaffUser); dummyStaffUser.Designation = "Mrs"; dummyStaffUser.Email = "*****@*****.**"; dummyStaffUser.EnableDst = false; dummyStaffUser.FirstName = "UpdatedFirstName"; dummyStaffUser.Greeting = "UpdatedGreetingtext"; StaffGroupCollection staffGroups = TestSetup.KayakoApiService.Staff.GetStaffGroups(); dummyStaffUser.GroupId = staffGroups[staffGroups.Count - 1].Id; dummyStaffUser.IsEnabled = false; dummyStaffUser.LastName = "UpdatedLastName"; dummyStaffUser.MobileNumber = "0798765432"; //Can't test signature as it doesn't come back from the Api //dummyStaffUser.Signature = "Signature Updated"; dummyStaffUser.TimeZone = "GMT BST"; dummyStaffUser.UserName = "******"; StaffUser updatedStaffUser = TestSetup.KayakoApiService.Staff.UpdateStaffUser(StaffUserRequest.FromResponseData(dummyStaffUser)); dummyStaffUser.FullName = String.Format("{0} {1}", dummyStaffUser.FirstName, dummyStaffUser.LastName); Assert.IsNotNull(updatedStaffUser); CompareStaffUsers(dummyStaffUser, updatedStaffUser); bool success = TestSetup.KayakoApiService.Staff.DeleteStaffUser(updatedStaffUser.Id); Assert.IsTrue(success); }
public bool Login(string loginId, string password) { if (string.IsNullOrWhiteSpace(loginId)) { throw new BizException("登录名不能为空!"); } if (string.IsNullOrWhiteSpace(password)) { throw new BizException("密码不能为空!"); } StaffUser user = CheckUserLogin(loginId, password); if (user == null) { throw new BizException("没有找到对应用户,登录失败"); } Cookie.Set("StaffUser", user.Id); return(true); }
public async Task <IActionResult> Login(LoginVM vm) { if (ModelState.IsValid) { if (vm.UserName != null) { StaffUser user = await userManager.FindByNameAsync(vm.UserName); if (user != null) { if (vm.Password != null) { await signInManager.SignOutAsync(); Microsoft.AspNetCore.Identity.SignInResult result = await signInManager.PasswordSignInAsync( user, vm.Password, false, false); if (result.Succeeded) { Helper.StaffUserLoggedIn = user; Helper.StaffProfileLoggedIn = Helper.DetermineProfile(staffProfRepo); //Redirects to the home index if login succeeds var role = Helper.StaffProfileLoggedIn.Role; if (role == "Staff") { return(Redirect("/")); } else if (role == "Admin") { return(Redirect("/Admin/Home")); } } } } } ModelState.AddModelError("", "Invalid name or password."); } return(View(vm)); }