public IHttpActionResult AddClicks(string id,string adId)
        {
            try
            {

                AuthRepository auth = new AuthRepository();

                auth.SetPlayerStatus(id,adId);

                return Ok();
            }
            catch (Exception)
            {

                return InternalServerError();
            }
        }
        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);
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        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();
            }
        }
Ejemplo n.º 5
0
        public IHttpActionResult ChangePassword(ChangePasswordDto model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            //IdentityResult result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword,
            //    model.NewPassword);
           

            try
            {
                AuthRepository repo = new AuthRepository();

                bool isTrue = repo.ChangePassword(model.Email, model.Password);

                if (!isTrue)
                {
                    return BadRequest("Error in changing Password. :D");
                }

                return Ok();
            }
            catch (Exception e)
            {
                
                return InternalServerError(e);
            }
        }