public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userManager = context.OwinContext.GetUserManager<PlayerUserManager>(); var player = new Player(); AuthRepository repo = new AuthRepository(); if(repo.FindUserByEmailAndPass(context.UserName, context.Password)) { player = repo.FindUser(context.UserName); } else { player.UserName = context.UserName; } Player user = await userManager.FindAsync(player.UserName, context.Password); if (!user.EmailConfirmed) { context.SetError("verification", "The account has not yet verified!"); return; } if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType); ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager, CookieAuthenticationDefaults.AuthenticationType); AuthenticationProperties properties = CreateProperties(user.UserName,user.IsPlayed); AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); }
public IHttpActionResult post(CombinationDto dto) { if(dto == null) { return InternalServerError(); } try { AuthRepository repo = new AuthRepository(); var data = repo.FindUserByUserName(dto.UserName); if (data == null) { data = repo.FindUser(dto.UserName); dto.UserName = data.UserName; if (dto.UserName == null) { return InternalServerError(); } } PlayerModel account = new PlayerModel() { FirstName = data.FirstName, LastName = data.LastName, Email = data.Email }; String Message = new EmailMessage(account).ParseCombination(dto.Combination); String Header = MessageTemplate.MessageTitle; Email mail = new Email(Header, Message, account); mail.SendEmail(); return Ok(); } catch (Exception) { return InternalServerError(); } }
public IHttpActionResult post(RecoverDto dto) { // recovery procedures here if(dto == null) { //throw new NullDtoException(); return InternalServerError(); } AuthRepository repo = new AuthRepository(); try { int confirmationNumber = new RecoveryCode().generateCode(); var data = repo.FindUser(dto.userEmail); if(data == null) { return InternalServerError(); } PlayerModel account = new PlayerModel() { FirstName = data.FirstName, LastName = data.LastName, Email = data.Email }; String Message = new EmailMessage(account).ParseRecover(confirmationNumber); String Header = MessageTemplate.MessageTitle; Email mail = new Email(Header, Message, account); mail.SendEmail(); return Ok(confirmationNumber); } catch(Exception) { return InternalServerError(); } }