Ejemplo n.º 1
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Home");
            }

            if (ModelState.IsValid)
            {

                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    new UsersManager().AddOrUpdateUser(new UserDTO() { UserID = model.Email });
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View("~/Views/Home/NoteeFY.cshtml");
        }
Ejemplo n.º 2
0
 public async Task<ActionResult> Register(RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
         var result = await UserManager.CreateAsync(user, model.Password);
         if (result.Succeeded)
         {
             new UsersManager().AddOrUpdateUser(new UserDTO() { UserID = model.Email });
             await SignInManager.SignInAsync(user, false, false);
             return RedirectToAction("Index", "Home");
         }
         else
         {
             var errorData = result.Errors.ToArray();
             if (errorData.Length == 2 && errorData[0].Split(' ').First() == "Name")
             {
                 var error = "Adres email " + model.Email + " jest już zajęty";
                 ModelState.AddModelError("", error);
             }
             else
             {
                 AddErrors(result);
             }
         }    
     }
     return View(model);
 }