Esempio n. 1
0
 public async Task<ActionResult> GoogleLoginCallback(string returnUrl)
 {
     ExternalLoginInfo loginInfo = await AuthManager.GetExternalLoginInfoAsync();
     AppUser user = await UserManager.FindAsync(loginInfo.Login);
     if (user == null)
     {
         user = new AppUser
         {
             Email = loginInfo.Email,
             UserName = loginInfo.DefaultUserName,
             City = Cities.London,
             Country = Countries.UK
         };
         IdentityResult result = await UserManager.CreateAsync(user);
         if (!result.Succeeded)
         {
             return View("Error", result.Errors);
         }
         else
         {
             result = await UserManager.AddLoginAsync(user.Id, loginInfo.Login);
             if (!result.Succeeded)
             {
                 return View("Error", result.Errors);
             }
         }
     }
     ClaimsIdentity ident = await UserManager.CreateIdentityAsync(user,
     DefaultAuthenticationTypes.ApplicationCookie);
     ident.AddClaims(loginInfo.ExternalIdentity.Claims);
     AuthManager.SignIn(new AuthenticationProperties
     {
         IsPersistent = false
     }, ident);
     return Redirect(returnUrl ?? "/");
 }
Esempio n. 2
0
 public async Task <ActionResult> CreateUser(CreateModel model)
 {
     if (ModelState.IsValid)
     {
         AppUser user = new AppUser
         {
             UserName = model.Name,
             Email = model.Email
         };
         IdentityResult result = await UserManager.CreateAsync(user, model.Password);
         if (result.Succeeded)
         {
             return RedirectToAction("UserIndex");
         }
         else
         {
             AddErrorsFromResult(result);
         }
     }
     return View(model);
 }