Example #1
0
        public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            return(Task.Factory.StartNew(() =>
            {
                var username = context.UserName;
                var password = context.Password;
                HomeController hc = new HomeController();
                UmUserMaster user = new UmUserMaster();
                user = hc.GetUserByCredentials(username, password);

                if (user != null)
                {
                    var claims = new List <Claim>()
                    {
                        new Claim(ClaimTypes.Name, user.UserName),
                        new Claim("UserId", user.ID.ToString())
                    };

                    ClaimsIdentity OAuthIdentity = new ClaimsIdentity(claims, Startup.OAuthOption.AuthenticationType);
                    context.Validated(new AuthenticationTicket(OAuthIdentity, new AuthenticationProperties()
                    {
                    }));
                }
                else
                {
                    context.SetError("invalid_grant", "Error");
                }
            }));
        }
        public IHttpActionResult PostUmUserMaster(UmUserMaster umUserMaster)
        {
            db.UmUserMasters.Add(umUserMaster);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = umUserMaster.ID }, umUserMaster));
        }
        public IHttpActionResult PutUmUserMaster(int id, UmUserMaster umUserMaster)
        {
            if (id != umUserMaster.ID)
            {
                return(BadRequest());
            }

            db.Entry(umUserMaster).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UmUserMasterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetUmUserMaster(int id)
        {
            UmUserMaster umUserMaster = db.UmUserMasters.Find(id);

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

            return(Ok(umUserMaster));
        }
        public IHttpActionResult DeleteUmUserMaster(int id)
        {
            UmUserMaster umUserMaster = db.UmUserMasters.Find(id);

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

            db.UmUserMasters.Remove(umUserMaster);
            db.SaveChanges();

            return(Ok(umUserMaster));
        }
Example #6
0
        public UmUserMaster GetUserByCredentials(string UserId, string Password)
        {
            if (UserId == null || Password == null)
            {
                return(null);
            }

            UmUserMaster user = db.UmUserMasters.Where(R => R.UserId == UserId && R.UserPassword == Password).FirstOrDefault();

            if (user != null)
            {
                user.UserPassword = string.Empty;
            }

            return(user);
        }