Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new Player() { 
                UserName = model.UserName,
                Email = model.Email,
                Address1 = model.Address1,
                Address2 = model.Address2,
                BirthDate = model.BirthDate,
                FirstName = model.FirstName,
                LastName = model.LastName,
                Location = model.Location,
                Gender = model.Gender,
                ContactNumber = model.ContactNumber
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

           
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            PlayerModel account = new PlayerModel() { 
                UserName = user.UserName,
                Email = user.Email,
                FirstName = user.FirstName,
                LastName = user.LastName
            };

            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            var urlEncode = HttpUtility.UrlEncode(code);
            var callBackUrl = "/register/confirmation/" + user.Id + "/token?code=" + urlEncode; 
            await UserManager.SendEmailAsync(user.Id, "Confirm your Account !", "Please confirm your account by clicking this link: <a href=\""
                                               + callBackUrl + "\">link</a>");

            String message = new EmailMessage(account).ParseNotify();

           

            string url = "Please confirm your account by clicking this link: <a href=\"" +
                                               "http://"+ HttpContext.Current.Request.Url.Authority + callBackUrl + "\">link</a>";
            Email mail = new Email(MessageTemplate.MessageTitle, url, account);

            mail.SendEmail();

            return Ok();
        }
Exemplo 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();
            }
        }