Example #1
0
        public ManagerLoginResponse ManagerLogin(ManagerLoginRequest request)
        {
            Log.Information("LCManagerPartner ManagerLogin {Login}", request.Login);
            var result      = new ServerManagerLogin();
            var returnValue = result.ProcessRequest(cnn, request);

            return(returnValue);
        }
Example #2
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            //return base.GrantResourceOwnerCredentials(context);
            string        connectionString = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;
            SqlConnection cnn = new SqlConnection(connectionString);

            ManagerLoginRequest request = new ManagerLoginRequest
            {
                Phone    = Convert.ToInt64(context.UserName),
                Password = context.Password
            };
            var result = new ServerManagerLogin();
            var authentificationResult = result.ProcessRequest(cnn, request);

            if (authentificationResult.ErrorCode == 0)
            {
                identity.AddClaim(new Claim(ClaimTypes.Role, authentificationResult.RoleName));
                //identity.AddClaim(new Claim("username", context.UserName));
                identity.AddClaim(new Claim(ClaimTypes.MobilePhone, context.UserName));
                context.Validated(identity);
            }
            else
            {
                context.SetError("invalid_grant", "Provided username and password is incorrect");
                return;
            }

            //if (context.UserName == "admin" && context.Password == "admin")
            //{
            //    identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));
            //    identity.AddClaim(new Claim("username", "admin"));
            //    identity.AddClaim(new Claim(ClaimTypes.Name, "Alexander Smirnov"));
            //    context.Validated(identity);
            //}
            //else if(context.UserName == "user" && context.Password == "user")
            //{
            //    identity.AddClaim(new Claim(ClaimTypes.Role, "user"));
            //    identity.AddClaim(new Claim("username", "user"));
            //    identity.AddClaim(new Claim(ClaimTypes.Name, "Vasya Pupkin"));
            //    context.Validated(identity);
            //}
            //else
            //{
            //    context.SetError("invalid_grant", "Provided username and password is incorrect");
            //    return;
            //}
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            //return base.GrantResourceOwnerCredentials(context);
            string        connectionString = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;
            SqlConnection cnn = new SqlConnection(connectionString);

            ManagerLoginRequest request = new ManagerLoginRequest
            {
                Login    = context.UserName,
                Password = context.Password
            };
            var result = new ServerManagerLogin();
            var authentificationResult = result.ProcessRequest(cnn, request);

            if (authentificationResult.ErrorCode == 0)
            {
                foreach (var c in authentificationResult.Roles)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, c));
                }
                //identity.AddClaim(new Claim("username", context.UserName));
                identity.AddClaim(new Claim("user", context.UserName));
                if (authentificationResult.Operator > 0)
                {
                    identity.AddClaim(new Claim("oper", authentificationResult.Operator.ToString()));
                }
                if (authentificationResult.Partner > 0)
                {
                    identity.AddClaim(new Claim("partner", authentificationResult.Partner.ToString()));
                }
                if (authentificationResult.Pos > 0)
                {
                    identity.AddClaim(new Claim("pos", authentificationResult.Pos.ToString()));
                }
                if (!string.IsNullOrEmpty(authentificationResult.PosCode))
                {
                    identity.AddClaim(new Claim("poscode", authentificationResult.PosCode));
                }
                if (authentificationResult.DefaultPartner > 0)
                {
                    identity.AddClaim(new Claim("defaultpartner", authentificationResult.DefaultPartner.ToString()));
                }
                if (authentificationResult.DefaultPos > 0)
                {
                    identity.AddClaim(new Claim("defaultpos", authentificationResult.DefaultPos.ToString()));
                }
                if (!string.IsNullOrEmpty(authentificationResult.DefaultPosCode))
                {
                    identity.AddClaim(new Claim("defaultposcode", authentificationResult.DefaultPosCode));
                }
                identity.AddClaim(new Claim("permissioncode", authentificationResult.PermissionCode));
                context.Validated(identity);
            }
            else
            {
                //Пишем текст ошибки
                context.SetError("invalid_grant", "Provided username and password is incorrect");

                //Добавляем в заголовок наш флаг (константу), он будет проверен посредником CustomAuthenticationMiddleware
                context.Response.Headers.Add(ServerGlobalVariables.OwinStatusFlag, new[] { ((int)HttpStatusCode.Unauthorized).ToString() });
            }
        }