コード例 #1
0
        private ClaimsIdentity GetIdentity(string username, string password)
        {
            var users = DBCarServiceDL_ADMIN.SearchAdmin(username);

            if (users != null)
            {
                if (users.password != GetCode.Hash(password))
                {
                    return(null);
                }

                else
                {
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimsIdentity.DefaultNameClaimType, users.login),
                        new Claim(ClaimsIdentity.DefaultRoleClaimType, users.role)
                    };

                    ClaimsIdentity claimsIdentity =
                        new ClaimsIdentity(claims, "Token",
                                           ClaimsIdentity.DefaultNameClaimType,
                                           ClaimsIdentity.DefaultRoleClaimType);

                    return(claimsIdentity);
                }
            }
            return(null);
        }
コード例 #2
0
        public JsonResult Post([FromBody] JObject value)
        {
            AdminModel candidate = new AdminModel()
            {
                login    = value["login"].ToString(),
                password = GetCode.Hash(value["password"].ToString()),
                role     = value["role"].ToString()
            };

            var result = DBCarServiceDL_ADMIN.SearchAdmin(candidate.login);

            if (result == null)
            {
                var temp = DBCarServiceDL_ADMIN.AdminADD(candidate);
                if (temp > 0)
                {
                    return(new JsonResult(new ResponsModel()
                    {
                        status = true
                    }));
                }
                else
                {
                    return(new JsonResult(new ResponsModel()
                    {
                        status = false, description = "registration failed"
                    }));
                }
            }
            else
            {
                return(new JsonResult(new ResponsModel()
                {
                    status = false, description = "already exists"
                }));
            }
        }