Esempio n. 1
0
        public ActionResult SignIn(SigInModel signIn)
        {
            Account account = new Account()
            {
                MailId   = signIn.UserName,
                Password = signIn.Password,
            };

            account = UserBL.Login(account);

            try
            {
                if (account.Role == "Admin")
                {
                    return(RedirectToAction("DisplayDoctorDetails", "Admin"));
                }
                else
                {
                    return(RedirectToAction("Index", "Patient"));
                }
            }
            catch (Exception)
            {
                Response.Write("Enter the correct username and password");
            }
            return(View());
        }
Esempio n. 2
0
        public async Task <ActionResult> Login(string id, SigInModel model)
        {
            if (ModelState.IsValid)
            {
                IDictionary <string, object> env = Request.GetOwinContext().Environment;

                AuthenticateDto authenticateResult = await _mediator.Send(new AuthenticateCommand
                {
                    UserName = model.UserName,
                    Password = model.Password
                });

                if (authenticateResult.AccountStatus == Wdc.DirectoryLib.Types.AccountStatus.Success)
                {
                    List <Claim> claims = new List <Claim>();
                    if (authenticateResult.User.JpegPhoto != null)
                    {
                        new Claim(Common.Constants.DtClaimTypes.UserImage, Convert.ToBase64String(authenticateResult.User.JpegPhoto));
                    }

                    env.IssueLoginCookie(new IdentityServer3.Core.Models.AuthenticatedLogin
                    {
                        AuthenticationMethod = "Cookies",
                        Subject         = authenticateResult.User.DisplayName,
                        Name            = authenticateResult.User.SamAccountName,
                        Claims          = claims,
                        PersistentLogin = true
                    });

                    ClaimsPrincipal user = (ClaimsPrincipal)User;
                    IdentityServer3.Core.Models.SignInMessage msg = env.GetSignInMessage(id);
                    string returnUrl = msg.ReturnUrl;

                    env.RemovePartialLoginCookie();

                    return(Redirect(returnUrl));
                }
                else
                {
                    ModelState.AddModelError("", authenticateResult.Message);
                }
            }

            return(View(model));
        }