private async Task LoadSharedKeyAndQrCodeUriAsync(MLUser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }
Exemplo n.º 2
0
        public MLUser Login(MLUser objMLUser)
        {
            MLUser objMLUserInfo = new MLUser();

            using (OnlineTestDBEntities dbContext = new OnlineTestDBEntities())
            {
                var userInfo = dbContext.tblUsers.Where(x => x.EmailID == objMLUser.EmailID && x.Password == x.Password && x.StatusID == 1).Select(x => x).FirstOrDefault();
                if (userInfo != null)
                {
                    objMLUserInfo.UserID     = userInfo.UID;
                    objMLUserInfo.FName      = userInfo.FName;
                    objMLUserInfo.LName      = userInfo.LName;
                    objMLUserInfo.FullName   = objMLUserInfo.GetFullName(objMLUser.FName, objMLUser.LName);
                    objMLUserInfo.DOB        = userInfo.DOB;
                    objMLUserInfo.UserTypeID = userInfo.UserTypeID ?? 2;
                }
            }

            return(objMLUserInfo);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new MLUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new MLUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemplo n.º 5
0
 public ActionResult Login(MLUser objMLUser)
 {
     if (!string.IsNullOrEmpty(objMLUser.EmailID) && !string.IsNullOrEmpty(objMLUser.Password))
     {
         objBLUser = new BLUser();
         var objUserInfo = objBLUser.Login(objMLUser);
         if (objUserInfo != null)
         {
             if (objUserInfo.UserTypeID == Constants.USERTYPEADMIN)
             {
                 return(RedirectToAction("Default", "Home", new { Area = "Admin" }));
             }
             else
             {
                 return(RedirectToAction("Default", "Home", new { Area = "User" }));
             }
         }
         return(View());
     }
     else
     {
         return(View());
     }
 }
Exemplo n.º 6
0
        public ActionResult Login()
        {
            MLUser objMLUser = new MLUser();

            return(View(objMLUser));
        }
Exemplo n.º 7
0
 public MLUser Login(MLUser objMLUser)
 {
     objDALUser = new DALUser();
     return(objDALUser.Login(objMLUser));
 }