Пример #1
0
        public async Task <User> FindByUserNameAsync(string userName)
        {
            userName.ThrowIfNull("userName");

            var appIdentityUser = await _userManager.FindByNameAsync(userName);

            var user = IdentityModelFactory.Create(appIdentityUser);

            return(user);
        }
        public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByNameAsync(model.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                // Send an email with this link
                //var code = await _userManager.GeneratePasswordResetTokenAsync(user);
                //var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                //await _emailSender.SendEmailAsync(model.Email, "Reset Password",
                //   "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");
                //return View("ForgotPasswordConfirmation");
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #3
0
        public async System.Threading.Tasks.Task <ActionResult> LogOn(string username, string password, bool?staySignedIn, string returnUrl)
        {
            var userStore = new Microsoft.AspNet.Identity.EntityFramework.UserStore <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>();
            var manager   = new Microsoft.AspNet.Identity.UserManager <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(userStore);



            var user = await manager.FindByNameAsync(username);


            bool result = await manager.CheckPasswordAsync(user, password);

            if (result)
            {
                if (user.EmailConfirmed)
                {
                    //I have some options: log them in, or I can send them an email to "Confirm" their account details.'
                    //I don't have email set up this week, so we'll come back to that.

                    //This authentication manager will create a cookie for the current user, and that cookie will be exchanged on each request until the user logs out
                    var authenticationManager = HttpContext.GetOwinContext().Authentication;
                    var userIdentity          = await manager.CreateIdentityAsync(user, Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie);

                    authenticationManager.SignIn(new Microsoft.Owin.Security.AuthenticationProperties()
                    {
                    }, userIdentity);
                }
                else
                {
                    ViewBag.Error = new string[] { "Your email address has not been confirmed." };
                    return(View());
                }
            }
            else
            {
                ViewBag.Error = new string[] { "Unable to Log In, check your username and password" };
                return(View());
            }
            if (string.IsNullOrEmpty(returnUrl))
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(Redirect(returnUrl));
            }
        }
 protected async virtual Task <TUser> FindUserAsync(string username)
 {
     return(await userManager.FindByNameAsync(username));
 }
Пример #5
-1
        public static ApplicationUser GetApplicationUser()
        {
            ApplicationDbContext db = new ApplicationDbContext();
            var store = new Microsoft.AspNet.Identity.EntityFramework.UserStore<VSMR12.Models.ApplicationUser>(new VSMR12.Models.ApplicationDbContext());
            var userManager = new Microsoft.AspNet.Identity.UserManager<VSMR12.Models.ApplicationUser>(store);

            VSMR12.Models.ApplicationUser user = userManager.FindByNameAsync(System.Web.HttpContext.Current.User.Identity.Name).Result;

            return user;
        }
Пример #6
-1
        public static vResource GetResource()
        {
            ApplicationDbContext db = new ApplicationDbContext();
            var store = new Microsoft.AspNet.Identity.EntityFramework.UserStore<VSMR12.Models.ApplicationUser>(new VSMR12.Models.ApplicationDbContext());
            var userManager = new Microsoft.AspNet.Identity.UserManager<VSMR12.Models.ApplicationUser>(store);

            VSMR12.Models.ApplicationUser user = userManager.FindByNameAsync(System.Web.HttpContext.Current.User.Identity.Name).Result;

            vResource resource = db.vResource.Find(user.UserId);

            return resource;
        }