Beispiel #1
0
 public async Task<ActionResult> UserSettings(UserSettings model, params string[] selectedRole)
 {
     if (!Request.IsAjaxRequest())
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
     if (user == null)
     {
         return Json(new { success = false, type = 1, message = "Error! User not found." }, JsonRequestBehavior.AllowGet);
     }
     user.TwoFactorEnabled = model.TwoFactorEnabled;
     var updateUser = await UserManager.UpdateAsync(user);
     return !updateUser.Succeeded ?
            Json(new { success = false, type = 1, message = "Error! " + updateUser.Errors.FirstOrDefault() }, JsonRequestBehavior.AllowGet) :
            Json(new { success = true, type = 3, message = "Settings updated!" }, JsonRequestBehavior.AllowGet);
 }
Beispiel #2
0
 public async Task<ActionResult> UserSettings()
 {
     if (!Request.IsAjaxRequest())
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
     if (user == null)
     {
         return Json(new { success = false, type = 1, message = "Error! User cannot be null." }, JsonRequestBehavior.AllowGet);
     }
     var userSettings = new UserSettings()
     {
         Username = user.UserName,
         TwoFactorEnabled = user.TwoFactorEnabled
     };
     return (PartialView("_UserSettings", userSettings));
 }