public object ValidateCustomer([FromBody] JObject customer)
        {
            string userName = customer.Value <string>("userName");
            string pwd      = customer.Value <string>("password");
            var    user     = authService.GetUser(userName, pwd);

            if (user == null)
            {
                return(null);
            }
            return(new
            {
                Address = user.Address,
                CustomerID = user.CustomerID,
                DateOfBirth = "28-06-1995",
                Email = user.Email,
                Name = user.Name,
                PhoneNumber = user.PhoneNumber,
                Password = "",
                Sex = user.Sex,
                Role = user.Role
            });
        }
Esempio n. 2
0
        public async Task <IActionResult> Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Invalid username/password");
                return(View());
            }
            var user = new User("", "", model.Username, model.Password);

            using (var context = new BPContext())
            {
                if (UserAuthentication.IsValidUser(user, context))
                {
                    var temp   = UserAuthentication.GetUser(user.Username, user.Password, context);
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.Name, temp.FirstName),
                        new Claim("FullName", temp.ToString()),
                        new Claim(ClaimTypes.Role, temp.Access.ToString()),
                    };

                    var claimsIdentity = new ClaimsIdentity(
                        claims, CookieAuthenticationDefaults.AuthenticationScheme);

                    var authProperties = new AuthenticationProperties
                    {
                        //AllowRefresh = <bool>,
                        // Refreshing the authentication session should be allowed.

                        //ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10),
                        // The time at which the authentication ticket expires. A
                        // value set here overrides the ExpireTimeSpan option of
                        // CookieAuthenticationOptions set with AddCookie.

                        //IsPersistent = true,
                        // Whether the authentication session is persisted across
                        // multiple requests. Required when setting the
                        // ExpireTimeSpan option of CookieAuthenticationOptions
                        // set with AddCookie. Also required when setting
                        // ExpiresUtc.

                        //IssuedUtc = <DateTimeOffset>,
                        // The time at which the authentication ticket was issued.

                        //RedirectUri = <string>
                        // The full path or absolute URI to be used as an http
                        // redirect response value.
                    };

                    await HttpContext.SignInAsync(
                        CookieAuthenticationDefaults.AuthenticationScheme,
                        new ClaimsPrincipal(claimsIdentity),
                        authProperties);

                    if (model.ReturnURL != null && Url.IsLocalUrl(model.ReturnURL))
                    {
                        return(Redirect(model.ReturnURL));
                    }
                    return(RedirectToAction("GetPlayerRankings", "Performances"));
                }
                else
                {
                    return(View("Login"));
                }
            }
        }