コード例 #1
0
        public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            string       mode     = context.UserName.Substring(0, 1);
            Organisation o        = null;
            bool         fail     = true;
            string       username = context.UserName.Substring(1);

            switch (mode)
            {
            case "m":
                o = OrganisationDA.CheckCredentials(username, context.Password);
                if (o != null)
                {
                    fail = false;
                }
                break;

            case "s":
                o = OrganisationDA.GetOrganisation(Int32.Parse(username));
                Employee employee = EmployeeDA.GetEmployeeByName(context.Password, o);
                if (o != null && employee != null)
                {
                    fail = false;
                }
                break;

            case "r":
                o = OrganisationDA.GetOrganisation(Int32.Parse(username));
                Customer customer = CustomerDA.GetCustomerByName(context.Password, o);
                if (o != null && customer != null)
                {
                    fail = false;
                }
                break;
            }
            if (fail)
            {
                context.Rejected();
                return(Task.FromResult(0));
            }

            var id = new ClaimsIdentity(context.Options.AuthenticationType);

            id.AddClaim(new Claim("userid", o.ID.ToString()));
            id.AddClaim(new Claim("dbname", o.DbName));
            id.AddClaim(new Claim("dblogin", o.DbLogin));
            id.AddClaim(new Claim("dbpass", o.DbPassword));

            context.Validated(id);
            return(Task.FromResult(0));
        }
コード例 #2
0
        public HttpResponseMessage Put(Password NewPas)
        {
            HttpResponseMessage response = null;
            Organisation        org      = new Organisation();

            org = OrganisationDA.CheckCredentials(NewPas.Login, NewPas.OldPassword);
            if (org != null)
            {
                OrganisationDA.ChangePassword(NewPas);
                response = Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                response = new HttpResponseMessage(HttpStatusCode.NotFound);
            }
            return(response);
        }
コード例 #3
0
        public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            Organisation o = OrganisationDA.CheckCredentials(context.UserName, context.Password);

            if (o == null)
            {
                context.Rejected();
                return(Task.FromResult(0));
            }

            var id = new ClaimsIdentity(context.Options.AuthenticationType);

            id.AddClaim(new Claim("dbname", o.DbName));
            id.AddClaim(new Claim("dblogin", o.DbLogin));
            id.AddClaim(new Claim("dbpass", o.DbPassword));

            context.Validated(id);
            return(Task.FromResult(0));
        }