public ActionResult RegisterPopup(int providerID, string registerAction)
        {
            var data  = repository.GetProvider(providerID);
            var model = new Models.ProviderPortal.RegisterVM
            {
                Password       = System.Web.Security.Membership.GeneratePassword(8, 1),
                RegisterAction = registerAction,
                Email          = data.Email,
                SendEmail      = true,
                ProviderID     = providerID,
                ProviderName   = data.CommonName
            };

            if (data.NPI != null)
            {
                model.ProviderNumber = data.NPI;
            }
            else
            {
                if (data.ProviderNumber != null)
                {
                    model.ProviderNumber = data.ProviderNumber;
                }
                else
                {
                    model.ProviderNumber = repository.GenerateProviderNumber(providerID);
                }
            }
            return(PartialView("RegisterPopup", model));
        }
 public ActionResult RegisterProvider(int providerID, string registerAction, string providerNumber, string password, string email, bool sendEmail)
 {
     try
     {
         var model = new Models.ProviderPortal.RegisterVM
         {
             RegisterAction = registerAction,
             Email          = email,
             Password       = password,
             ProviderID     = providerID,
             ProviderNumber = providerNumber,
             SendEmail      = sendEmail
         };
         repository.RegisterProvider(model);
         if (sendEmail == true && !string.IsNullOrEmpty(email))
         {
             var smtpInfo = AppService.Current.DataContext.SMTPAccounts.Where(x => x.AccountName == "Primary").SingleOrDefault();
             if (smtpInfo == null)
             {
                 throw new ArgumentNullException("Primary SMTP Account info has not been configured.");
             }
             var smtpAccount = new Domain.Email.SMTPAccount()
             {
                 Username           = smtpInfo.AccountUsername,
                 Password           = smtpInfo.AccountPassword,
                 Server             = smtpInfo.AccountServer,
                 Port               = smtpInfo.AccountPort.Value,
                 UseSSL             = smtpInfo.AccountUseSSL.Value,
                 AuthenticationMode = smtpInfo.AccountAuthMode.Value,
                 FromAddress        = smtpInfo.AccountDefaultFromAddress,
                 ReplyToAddress     = smtpInfo.AccountDefaultReplyAddress
             };
             string subject = "Applied Behavioral Provider Portal Account Created";
             string message = "An account has been created for you on the Applied Behavioral Provider Portal. You can log in to your new account at {0}\n\nUser Name: {1}\nPassword: {2}";
             message = String.Format(message, AppService.Current.Settings.ProviderPortalSite, providerNumber, password);
             DomainServices.Email.SMTP.Send(smtpAccount, subject, message, email);
         }
         return(Content("ok"));
     }
     catch (Exception e)
     {
         Dymeng.Framework.Exceptions.Handle(e, Global.GetWebInfo());
         return(Content("We're sorry, we ran into a problem registering this Provider.  Please contact your administrator or developer for details."));
     }
 }
Пример #3
0
        public void RegisterProvider(Models.ProviderPortal.RegisterVM model)
        {
            var ppu        = new ProviderPortalUser();
            var hashedPass = System.Web.Helpers.Crypto.HashPassword(model.Password);
            int aspNetId   = 0;

            using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ProviderPortalConnection"].ConnectionString))
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "INSERT INTO dbo.UserProfile (UserName) VALUES (@UserName);";
                    cmd.Parameters.AddWithValue("@UserName", model.ProviderNumber);
                    aspNetId        = cmd.InsertToIdentity();
                    cmd.CommandText = "INSERT INTO dbo.webpages_Membership (" +
                                      "UserID, CreateDate, IsConfirmed, PasswordFailuresSinceLastSuccess, Password, PasswordChangedDate, PasswordSalt" +
                                      ") VALUES (" +
                                      "@UserID, @CreateDate, @IsConfirmed, @PasswordFailuresSinceLastSuccess, @Password, @PasswordChangedDate, @PasswordSalt);";
                    cmd.Parameters.AddWithValue("@UserID", aspNetId);
                    cmd.Parameters.AddWithValue("@CreateDate", DateTime.Now);
                    cmd.Parameters.AddWithValue("@IsConfirmed", 1);
                    cmd.Parameters.AddWithValue("@PasswordFailuresSinceLastSuccess", 0);
                    cmd.Parameters.AddWithValue("@Password", hashedPass);
                    cmd.Parameters.AddWithValue("@PasswordChangedDate", DateTime.Now);
                    cmd.Parameters.AddWithValue("@PasswordSalt", "");
                    cmd.ExecuteNonQueryToInt();
                }

            ppu.AspNetUserID       = aspNetId;
            ppu.ProviderID         = model.ProviderID;
            ppu.ProviderUserNumber = model.ProviderNumber;

            using (SqlConnection conn = new SqlConnection(this.connectionString))
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "DELETE FROM dbo.ProviderPortalUsers WHERE AspNetUserID = @AspID; INSERT INTO dbo.ProviderPortalUsers (AspNetUserID, ProviderID, ProviderUserNumber) VALUES (" +
                                      "@AspID, @ProviderID, @UserNumber);";
                    cmd.Parameters.AddWithValue("@AspID", aspNetId);
                    cmd.Parameters.AddWithValue("@ProviderID", model.ProviderID);
                    cmd.Parameters.AddWithValue("@UserNumber", model.ProviderNumber);
                    cmd.InsertToIdentity();
                }
        }