Ejemplo n.º 1
0
 public static async Task ChangeAccountInfo(string id, ApplicationUser user)
 {
     var cntx = Cntx;
     UserServiceProxy usvc = new UserServiceProxy();
     var u = await usvc.LoadEntityByKeyAsync(cntx, id);
     if (u == null)
         return;
     u.FirstName = user.FirstName;
     u.LastName = user.LastName;
     if (u.IsFirstNameModified || u.IsLastNameModified)
         await usvc.AddOrUpdateEntitiesAsync(cntx, new UserSet(), new User[] { u });
     if (!string.IsNullOrEmpty(user.Email))
     {
         UserAppMemberServiceProxy mbsvc = new UserAppMemberServiceProxy();
         var mb = await mbsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.App.ID, id);
         if (mb != null)
         {
             mb.Email = user.Email;
             if (mb.IsEmailModified)
                 await mbsvc.AddOrUpdateEntitiesAsync(cntx, new UserAppMemberSet(), new UserAppMember[] { mb });
         }
     }
 }
Ejemplo n.º 2
0
 public async Task<ActionResult> Register(RegisterViewModel model)
 {
     if (CheckMemberInitStatus() && ModelState.IsValid)
     {
         var user = new ApplicationUser() { Username = model.UserName };
         user.Email = model.Email;
         var result = await UserManager.CreateAsync(user, model.Password);
         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);
 }
Ejemplo n.º 3
0
 public async Task<ActionResult> ChangeAccountInfo(ChangeAccountInfoModel model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         ApplicationUser user = new ApplicationUser { FirstName = model.FirstName, LastName = model.LastName };
         if (!string.IsNullOrEmpty(model.Email))
             user.Email = model.Email;
         await MembershipContext.ChangeAccountInfo(User.Identity.GetUserId(), user);
     }
     if (string.IsNullOrEmpty(returnUrl))
         return RedirectToAction("Index", "Home");
     else
         return Redirect(returnUrl);
 }
Ejemplo n.º 4
0
 private async Task SignInAsync(ApplicationUser user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
 }