Exemplo n.º 1
0
 public aymkResponse Login(string username, string password)
 {
     try
     {
         accountBL = new AccountBL();
         aymkResponse response = accountBL.Get(p => p.username == username && p.password == password);
         if (response.IsSuccess)
         {
             if (response.Data != null)
             {
                 return(response);
             }
             else
             {
                 return(new aymkResponse(aymkError.UsernamePasswordWrong, "aymk_api.database.account"));
             }
         }
         else
         {
             return(new aymkResponse(aymkError.UserNotFound, "aymk_api.database.account"));
         }
     }
     catch (System.Exception ex)
     {
         return(new aymkResponse(aymkError.GeneralError, "aymk_api.database.account", ex));
     }
 }
Exemplo n.º 2
0
        // OAuthAuthorizationServerProvider sınıfının kaynak erişimine izin verebilmek için ilgili GrantResourceOwnerCredentials metotunu override ediyoruz.
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });



            IAccountBL   accountBL = new AccountBL();
            aymkResponse response  = accountBL.Login(context.UserName, context.Password);

            if (response.IsSuccess)
            {
                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim("sub", context.UserName));
                identity.AddClaim(new Claim("role", "user"));
                context.Validated(identity);
            }
            else
            {
                context.SetError(response.Message, response.Detail);
            }
        }
Exemplo n.º 3
0
        public aymkResponse Register(Account item)
        {
            try
            {
                // general validation
                aymkResponse validateAccount = isValidAccount(item);
                if (!validateAccount.IsSuccess)
                {
                    return(validateAccount);
                }

                accountBL = new AccountBL();

                aymkResponse response = accountBL.Add(item);
                if (response.IsSuccess)
                {
                    return(response);
                }
                else
                {
                    if (response.Detail.Contains("UQ_Account_Email"))
                    {
                        return(new aymkResponse(aymkError.Register_Email_Exist));
                    }
                    else if (response.Detail.Contains("UQ_Account_Username"))
                    {
                        return(new aymkResponse(aymkError.Register_Username_Exist));
                    }
                    else
                    {
                        response.Message = aymkError.RegisterError.GetDescription();
                        return(response);
                    }
                }
            }
            catch (System.Exception ex)
            {
                return(new aymkResponse(aymkError.GeneralError, "aymk_api.database.account", ex));
            }
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "http://localhost:52981" });

            IAccountBL   accountBL = new AccountBL();
            aymkResponse response  = accountBL.Login(context.UserName, context.Password);

            if (response.IsSuccess)
            {
                ClaimsIdentity           oAuthIdentity   = new ClaimsIdentity(context.Options.AuthenticationType);
                ClaimsIdentity           cookiesIdentity = new ClaimsIdentity(context.Options.AuthenticationType);
                AuthenticationProperties properties      = CreateProperties(context.UserName);
                AuthenticationTicket     ticket          = new AuthenticationTicket(oAuthIdentity, properties);
                context.Validated(ticket);
                context.Request.Context.Authentication.SignIn(cookiesIdentity);
            }
            else
            {
                context.SetError("invalid_grant", response.Message);
                return;
            }
        }