예제 #1
0
        private void SignInUser(LoginByUsernamePassword_Result login, bool isPersistent)
        {
            // Initialization.
            var claims = new List <Claim>();

            try
            {
                // Setting
                claims.Add(new Claim(ClaimTypes.Name, login.username));
                claims.Add(new Claim(ClaimTypes.NameIdentifier, login.id.ToString()));
                var claimIdenties         = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
                var ctx                   = Request.GetOwinContext();
                var authenticationManager = ctx.Authentication;
                // Sign In.
                authenticationManager.SignIn(new AuthenticationProperties()
                {
                    IsPersistent = isPersistent
                }, claimIdenties);
            }
            catch (Exception ex)
            {
                // Info
                throw ex;
            }
        }
        public HttpResponseMessage Post([FromBody] LoginByUsernamePassword_Result users)
        {
            var  loginInfo = db.LoginByUsernamePassword(users.username, users.password).ToList();
            bool res;

            if (loginInfo != null && loginInfo.Count() > 0)
            {
                res = true;
            }
            else
            {
                res = false;
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(JsonConvert.SerializeObject(res), Encoding.UTF8, "application/json");
            return(response);
        }