Пример #1
0
            public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
            {
                context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

                //Check User
                AuthBL       rep  = new AuthBL();
                IdentityUser user = rep.FindUser(context.UserName, context.Password);

                //create toke
                if (user == null)
                {
                    context.SetError("User Not Found");
                }
                else
                {
                    ClaimsIdentity identity = new ClaimsIdentity(context.Options.AuthenticationType);
                    identity.AddClaim(new Claim("UserName", context.UserName));
                    if (rep.FinduserRole(context.UserName, context.Password) == "Admin")
                    {
                        identity.AddClaim(new Claim(identity.RoleClaimType, "Admin"));
                    }

                    else if (rep.FinduserRole(context.UserName, context.Password) == "User")
                    {
                        identity.AddClaim(new Claim(identity.RoleClaimType, "User"));
                    }

                    context.Validated(identity);
                }
            }
Пример #2
0
        public IHttpActionResult AddUser(UserMdel newuser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AuthBL          AuthBusLayer = new AuthBL();
            ApplicationUser OldUser      = AuthBusLayer.FindUser(newuser.UserName, newuser.Password);

            if (OldUser != null)
            {
                return(BadRequest("Exist Befor"));
            }

            IdentityResult res = AuthBusLayer.CreateUser(newuser);

            if (res.Succeeded)
            {
                return(Ok("User"));
            }
            string Errors = "";

            foreach (var item in res.Errors)
            {
                Errors += item + " ";
            }
            return(BadRequest(Errors));
        }
        public IHttpActionResult GetUSerID(LoginModel user)
        {
            AuthBL rep = new AuthBL();

            ApplicationUser res = rep.FindUser(user.UserName, user.Password);

            if (res != null)
            {
                if (res.IsDeleted == false)
                {
                    return(Ok(res.Id));
                }
            }
            return(NotFound());
        }