Esempio n. 1
0
 // POST validation api/<controller>
 public IHttpActionResult Post(AuthorizeRequestDto requestDto)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok());
 }
        public IHttpActionResult Post(AuthorizeRequestDto request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var authApp = _db.AuthorizedApps
                          .FirstOrDefault(i => i.AppToken == request.AppToken &&
                                          i.AppSecret == request.AppSecret &&
                                          DateTime.UtcNow < i.TokenExpiration);

            if (authApp == null)
            {
                return(Unauthorized());
            }

            var token = _tokenHelper.CreateToken(authApp);

            return(Ok(token));
        }
Esempio n. 3
0
 public JudgeDto PostAuthAuthorize(string raceId, AuthorizeRequestDto authorization)
 {
     return(apiAuthentication.Authorize(raceId, authorization));
 }
Esempio n. 4
0
        public async Task <IHttpActionResult> Login(AuthorizeRequestDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var userStore = new UserStore <TicketDeskUser>(context);

            var manager = new TicketDeskUserManager(userStore);
            TicketDeskSignInManager signinmanager = new TicketDeskSignInManager(manager, HttpContext.Current.GetOwinContext().Authentication);


            // var signinManager = manager.get.GetUserManager<TicketDeskSignInManager>();
            var user = manager.FindByEmail(model.Username);

            var validCredentials = signinmanager.UserManager.CheckPassword(user, model.Password);

            if (!validCredentials)
            {
                return(Unauthorized());
                //sample code to run if user's credentials is valid and before login
                //if (!manager.IsInRole(user.Id, "Administrators"))
                //{
                //    FailureText.Text = "you need a higher permission level in order to login";
                //    return;
                //}
            }

            //then sign in
            var result = signinmanager.PasswordSignIn(model.Username, model.Password, true, shouldLockout: false);


            switch (result)
            {
            case SignInStatus.Success:


                var dic = new Dictionary <string, Object>();
                dic.Add("username", user.UserName);
                dic.Add("userid", user.Id);
                return(Ok(dic));

            case SignInStatus.LockedOut:
                return(Unauthorized());
            }
            //var result = await SignInManager.PasswordSignInAsync(model.Username, model.Password, true, true);



            //if (result != SignInStatus.Success && model.Username.Contains("@"))
            //{
            //   var  user = await UserManager.FindByEmailAsync(model.Username);
            //    if (user != null)
            //    {
            //        result = await SignInManager.PasswordSignInAsync(user.UserName, model.Password, true, true);
            //    }

            //}



            //switch (result)
            //{
            //    case SignInStatus.Success:
            //        //  var token = _tokenHelper.CreateToken(authApp);
            //        return Ok(UserManager.FindByEmailAsync(model.Username));

            //    case SignInStatus.LockedOut:
            //        return Unauthorized();
            //}

            return(NotFound());
        }