Exemple #1
0
 public IActionResult Register([FromBody] RegistrationFormDataViewModel model)
 {
     if (ModelState.IsValid)
     {
         var result         = new { Succeeded = true };
         var passwordHasher = new PasswordHasher <string>();
         _commandSender.Send(new RegisterUserCommand
         {
             Email        = model.Email,
             PasswordHash = passwordHasher.HashPassword(model.Email, model.Password),
             UserName     = model.UserName,
             FirstName    = model.FirstName,
             LastName     = model.LastName
         });
         if (result.Succeeded)
         {
             return(Ok(new RegistrationResponseViewModel()));
         }
         else
         {
             var response = new RegistrationResponseViewModel
             {
                 //IsLockedOut = result.IsLockedOut,
                 //IsNotAllowed = result.IsNotAllowed,
                 //RequiresTwoFactor = result.RequiresTwoFactor,
             };
             return(BadRequest(response));
         }
     }
     else
     {
         return(BadRequest("Error"));
     }
 }
Exemple #2
0
        public async Task <RegistrationResponseViewModel> Register([FromBody] RegistrationFormDataViewModel model)
        {
            if (ModelState.IsValid)
            {
                var hostName       = GetHostName();
                var passwordHasher = new PasswordHasher <string>();
                try
                {
                    var queryResult = await _querySender.Send(new UserSearchQuery
                    {
                        Email          = model.Email,
                        ChannelId      = Channels.Feel,
                        SignUpMethodId = SignUpMethods.Regular,
                        PhoneCode      = model.PhoneCode
                    });

                    if (queryResult.Success)
                    {
                        return(new RegistrationResponseViewModel
                        {
                            Success = false,
                            IsExisting = true,
                        });
                    }
                    else
                    {
                        await _commandSender.Send(new RegisterUserCommand
                        {
                            Email          = model.Email,
                            PasswordHash   = passwordHasher.HashPassword(model.Email, model.Password),
                            UserName       = model.UserName,
                            FirstName      = model.FirstName,
                            LastName       = model.LastName,
                            ChannelId      = Channels.Feel,
                            SignUpMethodId = SignUpMethods.Regular,
                            PhoneCode      = model.PhoneCode,
                            PhoneNumber    = model.PhoneNumber,
                            Ip             = _clientIpProvider.Get(),
                            ReferralId     = model.ReferralId,
                            IsMailOpt      = model.IsMailOpt
                        });

                        var query = await _querySender.Send(new UserSearchQuery
                        {
                            Email          = model.Email,
                            ChannelId      = Channels.Feel,
                            SignUpMethodId = SignUpMethods.Regular,
                            PhoneCode      = model.PhoneCode
                        });

                        Messaging.Models.Emails.Email email = new Messaging.Models.Emails.Email();
                        email.To                   = model.Email;
                        email.From                 = "FeelitLIVE  <*****@*****.**>"; // XXX: TODO: Add feel email template
                        email.TemplateName         = "feelUserSignUp";
                        email.ConfigurationSetName = "FIL-Signup";
                        email.Variables            = new Dictionary <string, object>
                        {
                            ["activationurl"] = "<a href='https://" + hostName + "/activate/" + query.User.AltId.ToString() + "' style='margin -right:100px;'><img src='https://static1.feelitlive.com/images/feel-mail/activate-account.png' width='215' height='36' style='border:0' alt='Activate Your Account' /></a>",
                            ["sitename"]      = "feelitLIVE"
                        };
                        await _confirmationEmailSender.Send(email);

                        // adding user to MailChimp contacts
                        try
                        {
                            await _mailChimpProvider.AddFILMember(new MCUserModel
                            {
                                FirstName   = model.FirstName,
                                LastName    = model.LastName,
                                Email       = model.Email,
                                PhoneCode   = model.PhoneCode,
                                PhoneNumber = model.PhoneNumber,
                                IsCreator   = false,
                                SignUpType  = "Regular"
                            }, query.Country);
                        }
                        catch (Exception e)
                        {
                            _logger.Log(Logging.Enums.LogCategory.Error, e);
                        }

                        return(new RegistrationResponseViewModel {
                            Success = true, IsExisting = false,
                        });
                    }
                }
                catch (Exception ex)
                {
                    _logger.Log(Logging.Enums.LogCategory.Error, ex);
                    return(new RegistrationResponseViewModel
                    {
                        Success = false,
                        IsExisting = false,
                    });
                }
            }
            else
            {
                return(new RegistrationResponseViewModel
                {
                    Success = false,
                    IsExisting = false,
                });
            }
        }