コード例 #1
0
        public ActionResult SignIn(SigninViewModel member)
        {
            string Validatestr = memberservice.SigninCheck(member.Account, member.Password);

            if (String.IsNullOrEmpty(Validatestr))
            {
                string RoleData = memberservice.GetRole(member.Account);

                JwtService jwtService = new JwtService();
                string     CookieName = WebConfigurationManager.AppSettings["CookieName"].ToString();
                string     Token      = jwtService.GenerateToken(member.Account, RoleData);

                HttpCookie cookie = new HttpCookie(CookieName);
                cookie.Value = Server.UrlEncode(Token);

                Response.Cookies.Add(cookie);
                Response.Cookies[CookieName].Expires = DateTime.Now.AddMinutes(Convert.ToInt32(WebConfigurationManager.AppSettings["ExpireMinutes"]));

                return(RedirectToAction("Index", "Platform"));
            }
            else
            {
                ModelState.AddModelError("", Validatestr);
                return(View(member));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Signin(SigninViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result =
                    await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);

                if (result.Succeeded)
                {
                    if (!string.IsNullOrEmpty(model.ReturnUrl) && Url.IsLocalUrl(model.ReturnUrl))
                    {
                        return(Redirect(model.ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Incorrect email and (or) password.");
                }
            }
            return(View(model));
        }
コード例 #3
0
 public IActionResult SigninUser(SigninViewModel user)
 {
     if (ModelState.IsValid)
     {
         PasswordHasher <User> hasher = new PasswordHasher <User>();
         User myUser = _context.Users.SingleOrDefault(User => User.Email == user.Email);
         if (myUser != null)
         {
             if (hasher.VerifyHashedPassword(myUser, myUser.Password, user.Password) == PasswordVerificationResult.Success)
             {
                 HttpContext.Session.SetInt32("id", myUser.Id);
                 return(RedirectToAction("Index", "Dashboard"));
             }
             else
             {
                 TempData["Login Error"] = "Incorrect Password";
             }
         }
         else
         {
             TempData["Login Error"] = "This user does not exist.";
         }
     }
     else
     {
         foreach (var modelState in ModelState.Values)
         {
             foreach (var error in modelState.Errors)
             {
                 TempData[error.ErrorMessage] = error.ErrorMessage;
             }
         }
     }
     return(RedirectToAction("Signin"));
 }
コード例 #4
0
        public async Task <IActionResult> Signin(SigninViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = new User {
                    Email        = model.Email,
                    UserName     = model.Name,
                    RegisterDate = DateTime.Now,
                    LoginDate    = DateTime.Now,
                    Status       = "Unblocked"
                };
                // добавляем пользователя
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // установка куки
                    await _signInManager.SignInAsync(user, false);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            return(View(model));
        }
コード例 #5
0
        public async Task <IActionResult> TokenAuth(SigninViewModel model)
        {
            var issuer   = _configuration["Tokens:Issuer"];
            var audience = _configuration["Tokens:Audience"];
            var key      = _configuration["Tokens:Key"];

            if (ModelState.IsValid)
            {
                var signinResult =
                    await _signInManager.PasswordSignInAsync(model.Username, model.Password, false, false);

                if (signinResult.Succeeded)
                {
                    var user = await _userManager.FindByEmailAsync(model.Username);

                    if (user != null)
                    {
                        var claims = new[]
                        {
                            new Claim(JwtRegisteredClaimNames.Email, user.Email),
                            new Claim(JwtRegisteredClaimNames.Jti, user.Id),
                        };

                        var keyBytes = Encoding.UTF8.GetBytes(key);
                        var theKey   = new SymmetricSecurityKey(keyBytes);
                        var creds    = new SigningCredentials(theKey, SecurityAlgorithms.HmacSha256);
                        var token    = new JwtSecurityToken(issuer, audience, claims, expires: DateTime.Now.AddMinutes(30), signingCredentials: creds);

                        return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token) }));
                    }
                }
            }

            return(BadRequest());
        }
コード例 #6
0
        public async Task <ActionResult> Signin(SigninViewModel loginModel)
        {
            var model = new LoginViewModel(loginModel, new RegistrationViewModel(loginModel.ReturnUrl));

            if (!ModelState.IsValid)
            {
                return(View("Login", model));
            }

            var clientAccount =
                await _clientAccountsRepository.AuthenticateAsync(loginModel.Username, loginModel.Password) ??
                //ToDo: to remove when migrated to hashes
                await
                _clientAccountsRepository.AuthenticateAsync(loginModel.Username,
                                                            PasswordKeepingUtils.GetClientHashedPwd(loginModel.Password));

            if (clientAccount == null)
            {
                ModelState.AddModelError("Username", " ");
                ModelState.AddModelError("Password", "Invalid user");
                return(View("Login", model));
            }

            var identity = await _userManager.CreateUserIdentityAsync(clientAccount, loginModel.Username);

            await
            HttpContext.Authentication.SignInAsync("ServerCookie", new ClaimsPrincipal(identity),
                                                   new AuthenticationProperties());

            return(RedirectToLocal(loginModel.ReturnUrl));
        }
コード例 #7
0
        public ActionResult Signin(SigninViewModel model)
        {
            if (ModelState.IsValid && !User.Identity.IsAuthenticated)
            {
                var result = SignInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, false).Result;
                switch (result)
                {
                case SignInStatus.Success:
                    return(RedirectToAction("Index", "Home"));

                case SignInStatus.LockedOut:
                    ModelState.AddModelError("", "Аккаунт заблокирован");
                    break;

                case SignInStatus.Failure:
                    ModelState.AddModelError("", "Неверное имя пользователя или пароль");
                    break;

                case SignInStatus.RequiresVerification:
                    ModelState.AddModelError("", "Требуется дополнительная верификация");
                    break;
                }
            }
            return(View(model));
        }
コード例 #8
0
 public async Task <IActionResult> Signin([Bind("Email,Password")] SigninViewModel args)
 {
     try
     {
         User user            = _context.Users.Where(u => u.Email == args.Email).Single();
         bool isValidPassword = BCrypt.Net.BCrypt.Verify(args.Password, user.Password);
         if (isValidPassword)
         {
             await this.Login(user);
         }
         else
         {
             InvalidOperationException ex = new InvalidOperationException();
             ex.Data["field"] = "password";
             throw ex;
         }
     }
     catch (InvalidOperationException e)
     {
         if (e.Data["field"] != null && e.Data["field"].ToString() == "password")
         {
             return(RedirectToAction("Signin", new RouteValueDictionary(new { error = "Invalid Password" })));
         }
         return(RedirectToAction("Signin", new RouteValueDictionary(new { error = "Email Not found" })));
     }
     return(RedirectToAction("Index", ""));
 }
コード例 #9
0
        public async Task IShouldReturnBadRequestIfUserIsInactiveOnLogin()
        {
            var existentUser = new User
            {
                Id       = "asdf-aewrwe-asdfa",
                Email    = "*****@*****.**",
                IsActive = false
            };
            var viewModel = new SigninViewModel
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            var mockForDomainUserService = new Mock <IUserService>();

            mockForDomainUserService.Setup(service => service.GetUserByEmail(It.IsAny <string>()))
            .ReturnsAsync(existentUser)
            .Verifiable();

            var controller = new UserController(
                mockForDomainUserService.Object,
                null, null, null);

            var result = await controller.Login(viewModel);

            var    resultData = result as BadRequestObjectResult;
            string error      = resultData.Value?.GetType().GetProperty("error_description")?.GetValue(resultData.Value, null).ToString();

            Assert.IsInstanceOfType(resultData, typeof(BadRequestObjectResult));
            Assert.AreEqual(resultData.StatusCode, 400);
            Assert.AreEqual(error, "Usuario não esta ativo");
            mockForDomainUserService.VerifyAll();
        }
コード例 #10
0
 public async Task <IActionResult> Signin(SigninViewModel model)
 {
     if (ModelState.IsValid)
     {
         User user = new User {
             Email    = model.Email,
             UserName = model.Name,
         };
         var result = userManager.CreateAsync(user, model.Password).GetAwaiter().GetResult();
         if (result.Succeeded)
         {
             signInManager.SignInAsync(user, false).Wait();
             ViewBag.Status = 2;
             return(Redirect($"/Home/Index/{model.Name}"));
         }
         else
         {
             foreach (var error in result.Errors)
             {
                 ModelState.AddModelError(string.Empty, error.Description);
             }
         }
     }
     return(View(model));
 }
コード例 #11
0
        public async Task <IActionResult> Signin(SigninViewModel model, string returnUrl = null)
        {
            this.ViewData["ReturnUrl"] = returnUrl;

            if (this.ModelState.IsValid)
            {
                try
                {
                    var result = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, false);

                    if (result.Succeeded)
                    {
                        return(this.RedirectToLocal(returnUrl));
                    }

                    // I added the exclamation mark to make it more dramatic
                    this.TempData["ErrorMessage"] = "The username and/or password are incorrect!";

                    return(this.View(model));
                }
                catch (Exception)
                {
                    this.TempData["ErrorMessage"] = "Something bad happened while logging in...";

                    return(this.View(model));
                }
            }

            return(this.View(model));
        }
コード例 #12
0
        public async Task<ActionResult> Signin(SigninViewModel model)
        {
            if (ModelState.IsValid)
            {
                var pharmacy = await context.Pharmacies
                .SingleOrDefaultAsync(m => m.PharmacyName == model.PharmacyName && m.Password == model.Password);
                if (pharmacy == null)
                {
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View("Signin");
                }
                HttpContext.Session.SetString("userId", pharmacy.PharmacyName);
                var identity = new ClaimsIdentity(new[] {
                    new Claim(ClaimTypes.Name, model.PharmacyName),
                     new Claim(ClaimTypes.Role, "Pharmacy")
                }, CookieAuthenticationDefaults.AuthenticationScheme);

                var principal = new ClaimsPrincipal(identity);

                var login = HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);
            }
            else
            {
                return View("Signin");
            }
            return RedirectToAction("Index");
        }
コード例 #13
0
        public async Task <IActionResult> Signin(SigninViewModel model, string returnUrl)
        {
            if (string.IsNullOrEmpty(returnUrl))
            {
                returnUrl = "/";
            }
            ViewData["returnUrl"] = returnUrl;
            bool isLogin = false;
            var  user    = await _userManager.FindByNameAsync(model.UserName);

            if (user == null)
            {
                isLogin = false;
            }
            else
            {
                isLogin = await _userManager.CheckPasswordAsync(user, model.PassWord);
            }
            if (isLogin)
            {
                await _signInManager.SignInAsync(user, true);

                return(Redirect(returnUrl));
            }
            return(View(model));
        }
コード例 #14
0
        public async Task <IActionResult> SignIn(SigninViewModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    var user = await userManager.FindByNameAsync(model.phoneNumber);

                    if (user != null)
                    {
                        var passwordValidation = await signinManager.CheckPasswordSignInAsync(user, model.password, false);

                        if (passwordValidation.Succeeded)
                        {
                            await signinManager.SignInAsync(user, false);
                        }
                    }
                }
                else
                {
                    return(View(model));
                }
            }
            return(Redirect("/Home/Index"));
        }
コード例 #15
0
ファイル: AuthController.cs プロジェクト: Sefirosu/accounting
        public async Task<ActionResult> Signin(SigninViewModel vm, string returnUrl = null)
        {
            if (this.ModelState.IsValid)
            {
                var user = this.userRepository.GetAccountingUserByEmailOrUserName(vm.Username);

                if (user != null)
                {
                    var signInResult = await this.signInManager.PasswordSignInAsync(user, vm.Password, true, false);

                    if (signInResult.Succeeded)
                    {
                        this.Alert("Successfully signed in.", "success");

                        if (string.IsNullOrWhiteSpace(returnUrl))
                        {
                            return this.RedirectToAction("Index", "Index");
                        }
                        else
                        {
                            return this.Redirect(returnUrl);
                        }
                    }
                }
            }

            this.ViewBag.Error = "Incorrect username or password.";

            return this.View(vm);
        }
コード例 #16
0
        public async Task <IActionResult> Signin(SigninViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, false);

                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction("MFACheck"));
                }
                else
                {
                    if (!result.Succeeded)
                    {
                        ModelState.AddModelError("Login", "Cannot login.");
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }

            return(View(model));
        }
コード例 #17
0
        public async Task <IActionResult> GetSignin([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var signin = await _context.Signins.FindAsync(id);

            if (signin == null)
            {
                return(NotFound());
            }

            var viewModel = new SigninViewModel
            {
                Id         = signin.Id,
                TimeIn     = signin.TimeIn,
                TimeOut    = signin.TimeOut,
                EmployeeId = signin.EmployeeId,
                SiteId     = signin.SiteId
            };

            return(Ok(viewModel));
        }
コード例 #18
0
ファイル: AccountController.cs プロジェクト: XuanLoveN/bsp
        public ActionResult Signin(SigninViewModel model)
        {
            string captcha = base.CacheManager.Session.Get <string>("Captcha");

            if (!string.Equals(model.ValidateCode, captcha, System.StringComparison.CurrentCultureIgnoreCase))
            {
                ModelState.AddModelError("ValidateCode", "验证码输入错误");
                return(View());
            }

            IMessage <UserTicket> message = base.Facade.User.Signin(model.UserName, model.Password);

            if (message.Success)
            {
                if (model.Remember)
                {
                    base.CacheManager.Cookie.Set(Constants.SIGNINREMEMBERKEY, message.Entity.ParseToString());
                }
                //设置票证
                FormsAuthentication.SetAuthCookie(message.Entity.ParseToString(), false);
                return(Redirect(FormsAuthentication.DefaultUrl));
            }
            else
            {
                base.ErrorMessage = message.Content;
            }
            return(View(model));
        }
コード例 #19
0
        public async Task <ActionResult> Signin(SigninViewModel loginModel)
        {
            var model = new LoginViewModel(loginModel, new RegistrationViewModel(loginModel.ReturnUrl));

            if (!ModelState.IsValid)
            {
                return(View("Login", model));
            }

            AuthResponse authResult = await _registrationClient.AuthorizeAsync(new AuthModel
            {
                Email     = loginModel.Username,
                Password  = loginModel.Password,
                Ip        = this.GetIp(),
                UserAgent = this.GetUserAgent()
            });


            if (authResult.Status == AuthenticationStatus.Error)
            {
                ModelState.AddModelError("Username", " ");
                ModelState.AddModelError("Password", "Invalid user");
                return(View("Login", model));
            }

            var identity = await _userManager.CreateUserIdentityAsync(authResult.Account.Id, authResult.Account.Email, loginModel.Username);

            await HttpContext.Authentication.SignInAsync("ServerCookie", new ClaimsPrincipal(identity), new AuthenticationProperties());

            return(RedirectToLocal(loginModel.ReturnUrl));
        }
コード例 #20
0
        public async Task <IActionResult> Signin([FromBody] SigninViewModel model)
        {
            StatusCodeResult res = null;

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    res = Ok();
                    return(await Task.FromResult(res));
                }
                else
                {
                    res = NotFound();
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    Response.StatusCode = StatusCodes.Status409Conflict;
                    return(Json(ModelState.Values.SelectMany(v => v.Errors).ToList()));
                }
            }

            Response.StatusCode = StatusCodes.Status409Conflict;
            return(Json(ModelState.Values.SelectMany(v => v.Errors).ToList()));
        }
コード例 #21
0
        public async Task <IActionResult> Signin(SigninViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, false);

                if (result.Succeeded)
                {
                    var user = await _userManager.FindByEmailAsync(model.Username);

                    var userClaims = await _userManager.GetClaimsAsync(user);

                    //if (!userClaims.Any(x => x.Type == "Department"))
                    //{
                    //    ModelState.AddModelError("Claim", "User not in tech department.");
                    //    return View(model);
                    //}

                    if (await _userManager.IsInRoleAsync(user, "Member"))
                    {
                        return(RedirectToAction("Member", "Home"));
                    }
                }
                //else
                //{
                //    result.IsLockedOut gibi propertyleri kullanarak kontroller yapabiliriz.
                //    Ama güvenlik açısından mümkün olduğunca geri dönüş hatalarını açıklayıcı şekilde vermemeliyiz.
                //}


                ModelState.AddModelError("Login", "Cannot login.");
            }

            return(View(model));
        }
コード例 #22
0
        public async Task<ActionResult> Signin(SigninViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var user = await UserManager.FindByEmailAsync(model.Email);
            if (user == null)
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                return View(model);
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(user.UserName, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View(model);
            }
        }
コード例 #23
0
        public ActionResult ProcessSignin(SigninViewModel model)
        {
            var isValidLogin = CheckifValidPasswordAndSignInUsingModel(model);

            if (isValidLogin)
            {
                if (model.RedirectMode == RedirectMode.Link)
                {
                    return(Redirect(model.ReturnURL));
                }
                object routeValues = null;

                if (!String.IsNullOrWhiteSpace(model.JSONEncodedRouteValues))
                {
                    var js = new JavaScriptSerializer();

                    routeValues = js.Deserialize(model.JSONEncodedRouteValues,
                                                 Type.GetType(model.RouteValuesModelClassName));
                }
                return(RedirectToAction(model.RouteAction, model.RouteController, routeValues));
            }

            model.HasError = true;
            model.Password = String.Empty;

            return(RedirectToAction("Signin", model));
        }
コード例 #24
0
        public async Task <IActionResult> Signup(SigninViewModel signupmodel)
        {
            ApplicationUser user = new ApplicationUser
            {
                UserName   = signupmodel.UserName,
                Email      = signupmodel.Email,
                FirstName  = signupmodel.FirstName,
                LastName   = signupmodel.LastName,
                Country    = signupmodel.Country,
                NewStateId = signupmodel.NewStateId,
                LGAId      = signupmodel.LGAId,
                NewStates  = _account.FindNameByStateId(signupmodel.NewStateId),
                LGAs       = _account.FindNameByLocalId(signupmodel.LGAId)
            };

            var sign = await _account.CreateUser(user, signupmodel.Password);

            if (sign)
            {
                Alert("Account Created successfully", NotificationType.success);
                return(RedirectToAction("Login", "Account"));
                //return RedirectToAction("Index", "Home");
            }
            Alert("Account not created!", NotificationType.error);
            return(View());
            //ApplicationUser user = new ApplicationUser();
        }
コード例 #25
0
        public async Task <IActionResult> Signup(SigninViewModel signupmodel)
        {
            ApplicationUser user = new ApplicationUser();

            user.UserName = signupmodel.UserName;
            user.Email    = signupmodel.Email;

            var sign = await _account.CreateUser(user, signupmodel.Password);

            if (sign)
            {
                //Alert("Account Created successfully", NotificationType.success);
                return(RedirectToAction("Index", "Home"));
            }
            Alert("Account not created!", NotificationType.error);
            return(View());
            //ApplicationUser user = new ApplicationUser();


            //user.UserName = signup.Username;
            //user.Email = signup.Email;


            //var newUser = await _account.CreateUser(user, signup.Password);
            //if (newUser)
            //{
            //    Alert("Welcome "+ signup.Username + "!", NotificationType.success);
            //    return RedirectToAction("Index", "Home");
            //}

            //Alert("Author not created!", NotificationType.error);
            //return View();
        }
コード例 #26
0
        public async Task <IActionResult> LoginConfirm(SigninViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Login"));
            }
            //Model is Valid
            var CurrentUser = await _userManager.FindByNameAsync(model.Username);

            if (CurrentUser == null)
            {
                TempData["UserMessage"] = "اطلاعات کاربری صحیح نمی باشد";
                return(RedirectToAction("Login"));
            }
            //User Exists
            var CurrentUserStatus = CurrentUser.Status;
            var status            = await _signInManager.PasswordSignInAsync(CurrentUser, model.Password, model.IsRemember, false);

            if (status.Succeeded)
            {
                return(RedirectToAction("Index", "Home")); //successful signin
            }
            TempData["UserMessage"] = "اطلاعات کاربری صحیح نمی باشد";
            return(RedirectToAction("Login"));
        }
コード例 #27
0
        public async Task <IActionResult> SignIn(SigninViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await _signinManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, false);

                if (result.Succeeded)
                {
                    var user = await _userManager.FindByEmailAsync(model.UserName);

                    // Exp Get List of claims and and example hopw to use it
                    //var userClaims = await _userManager.GetClaimsAsync(user);
                    //if (!userClaims.Any(x=>x.Type == "Department"))
                    //{
                    //    ModelState.AddModelError("Claim", "User doesn\'t have claim department");
                    //    return View(model);
                    //}
                    if (await _userManager.IsInRoleAsync(user, "Admin"))
                    {
                        return(RedirectToAction("IndexZilnic", "AppAntrenament"));
                    }
                }
                else
                {
                    ModelState.AddModelError("Login", "Can\'t login.");
                }
            }
            return(View(model));
        }
コード例 #28
0
        public IActionResult Signin(SigninViewModel u)
        {
            if (!(ModelState.IsValid))
            {
                return(View());
            }

            List <User> Users = context.Users.ToList();

            if (Users.Count() < 1)
            {
                return(View("Index"));
            }

            foreach (User user in Users)
            {
                if (user.Email == u.Email)
                {
                    string hashString = u.Password + user.PassSalt;

                    // check for password
                    for (int i = 0; i < user.PassIterations; i++)
                    {
                        hashString = hash(hashString);
                    }

                    // If the password is right
                    if (user.PassHash == hashString)
                    {
                        GlobalStatic.userID    = user.UserId;
                        GlobalStatic.role      = user.Role;
                        GlobalStatic.Email     = user.Email;
                        GlobalStatic.FirstName = user.FirstName;
                        GlobalStatic.LastName  = user.LastName;
                        return(View("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Invalid email/password");
                        GlobalStatic.userID    = null;
                        GlobalStatic.role      = null;
                        GlobalStatic.Email     = null;
                        GlobalStatic.FirstName = null;
                        GlobalStatic.LastName  = null;

                        return(View());
                    }
                }
            }
            // no email matches
            ModelState.AddModelError(string.Empty, "Invalid email/password");
            GlobalStatic.userID    = null;
            GlobalStatic.role      = null;
            GlobalStatic.Email     = null;
            GlobalStatic.FirstName = null;
            GlobalStatic.LastName  = null;
            return(View());
        }
コード例 #29
0
        public IActionResult Signin(string error = null)
        {
            SigninViewModel signinvm = new SigninViewModel
            {
                ErrorMessage = error
            };

            return(View(signinvm));
        }
コード例 #30
0
        public IActionResult Authenticate([FromBody] SigninViewModel userCred)
        {
            var token = _tokenService.Authenticate(userCred.Username, userCred.Password);

            if (token == null)
            {
                return(Unauthorized());
            }
            return(Ok(token));
        }
コード例 #31
0
        private async Task AuthenticateUser(SigninViewModel loginDetails, UserToken tokenModel)
        {
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
            var identityUser = CreateCustomClaims(loginDetails, tokenModel);

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = false
            }, await Task.WhenAll(identityUser));
        }