private async Task SignInAsync(User user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); }
public JsonResult Delete(User user) { if (user.UserName != User.Identity.Name) { accountService.DeleteUser(user); return Json(true); } else { return Json(false); } }
public JsonResult Edit(CreateUserViewModel user) { if (ModelState.IsValid) { var updateUser = new User() { Id = user.Id.ToString(), UserName = user.UserName, FirstName = user.FirstName, LastName = user.LastName, SecretQuestion = user.SecretQuestion, SecretAnswer = user.SecretAnswer, Email = user.Email, Phone1 = user.Phone1, Phone2 = user.Phone2, Address1 = user.Address1, Address2 = user.Address2, City = user.City, State = user.State, Zip = user.Zip, Fax = user.Fax, CreateDate = DateTime.Now, Active = user.Active }; if (!string.IsNullOrEmpty(user.Password))// Password has changed { var newPwd = Oas.Service.Security.Encryptor.MD5Hash(user.Password); var result = UserManager.AddPassword(updateUser.Id, newPwd); } accountService.UpdateUserInfo(updateUser); return Json(true);//Json(updateUser, JsonRequestBehavior.AllowGet); } return Json(false); }
public bool DeleteUser(User user) { using (var dbContext = new DatabaseContext()) { var rDel = dbContext.Users.Include(t => t.Roles).FirstOrDefault(r => r.Id.Equals(user.Id)); if (rDel != null) { dbContext.Users.Remove(rDel); dbContext.SaveChanges(); return true; } } return false; }
public JsonResult Create(CreateUserViewModel user) { if (ModelState.IsValid) { var newUser = new User() { Id = Guid.NewGuid().ToString(), UserName = user.UserName, FirstName = user.FirstName, LastName = user.LastName, SecretQuestion = user.SecretQuestion, SecretAnswer = user.SecretAnswer, Email = user.Email, Phone1 = user.Phone1, Phone2 = user.Phone2, Address1 = user.Address1, Address2 = user.Address2, City = user.City, State = user.State, Zip = user.Zip, Fax = user.Fax, CreateDate = DateTime.Now, Active = user.Active }; try { //var password = Encryptor.MD5Hash(user.Password); IdentityResult result = UserManager.Create(newUser, user.Password); if (result.Succeeded) { UserManager.AddToRoleAsync(newUser.Id, UserRoles.Employee); ; return Json(true); } return Json(false); } catch (Exception ex) { //Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } } return Json(true); }
public bool CreateUser(User user, string password) { throw new NotImplementedException(); }
public bool CreateUser(User user) { throw new NotImplementedException(); }
public void UpdateUserInfo(User user) { accountRepository.Update(user); }
public async Task<ActionResult> Register(CreateUserViewModel model) { if (ModelState.IsValid) { var user = new User() { UserName = model.UserName }; var result = await UserManager.CreateAsync(user, "abcde12345-"); if (result.Succeeded) { await SignInAsync(user, isPersistent: false); return RedirectToAction("Index", "Home"); } else { AddErrors(result); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult LogOut() { Session["IsLock"] = true; var userInfo = accountService.Get(User.Identity.GetUserId()); User user = new TDevs.Domain.User() { UserName = userInfo.UserName, FirstName = userInfo.FirstName, LastName = userInfo.LastName, Email = userInfo.Email }; Session["User"] = user; AuthenticationManager.SignOut(); //FormsAuthentication.RedirectToLoginPage("/Home/LockScreen"); return Json(user, JsonRequestBehavior.AllowGet); }
public ActionResult LockScreen() { Session["IsLock"] = true; var userInfo = accountService.Get(User.Identity.GetUserId()); User user = new TDevs.Domain.User() { UserName = userInfo.UserName, FirstName = userInfo.FirstName, LastName = userInfo.LastName, Email = userInfo.Email }; Session["User"] = user; AuthenticationManager.SignOut(); return RedirectToAction("Index", "Home"); }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Manage"); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new User() { UserName = model.UserName }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInAsync(user, isPersistent: false); return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); }