public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();

            ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }

            //validate the user is active
            AditionalAccountOperations ac = new AditionalAccountOperations();
            bool result = await ac.IsEnable(context.UserName);

            if (result == false)
            {
                context.SetError("invalid_user", "The username is disable");
                return;
            }

            ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                OAuthDefaults.AuthenticationType);

            ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                  CookieAuthenticationDefaults.AuthenticationType);

            AuthenticationProperties properties = CreateProperties(user);
            AuthenticationTicket     ticket     = new AuthenticationTicket(oAuthIdentity, properties);

            context.Validated(ticket);
            context.Request.Context.Authentication.SignIn(cookiesIdentity);
        }
Exemplo n.º 2
0
        public async Task <HttpResponseMessage> Delete(String idUser)
        {
            try
            {
                if (idUser == null || idUser.Trim() == String.Empty)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Parámetro nulo"));
                }
                else
                {
                    AditionalAccountOperations ac = new AditionalAccountOperations();
                    await ac.Delete(idUser);

                    return(Request.CreateResponse(HttpStatusCode.OK, idUser));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 3
0
        public async Task <HttpResponseMessage> GetUsers([FromUri] int customer)
        {
            try
            {
                if (customer != 0) //zero is equals to null
                {
                    AditionalAccountOperations ac = new AditionalAccountOperations();
                    List <IDUser> data            = await ac.GetUsers(customer);

                    return(Request.CreateResponse(HttpStatusCode.OK, data));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Parámetro nulo"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemplo n.º 4
0
        public async Task <HttpResponseMessage> UpdateStatus([FromBody] IDUser user)
        {
            try
            {
                if (user != null)
                {
                    AditionalAccountOperations ac = new AditionalAccountOperations();
                    await ac.UpdateStatus(user);

                    return(Request.CreateResponse(HttpStatusCode.OK, user));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Parámetro nulo"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }