public async Task <ActionResult> Create(UserProfile model)
        {
            //return View();

            if (ModelState.IsValid)
            {
                string autoGeneratedPassword = Membership.GeneratePassword(8, 2);

                try
                {
                    //Create User
                    WebSecurity.CreateUserAndAccount(
                        model.UserName,
                        autoGeneratedPassword,
                        propertyValues: new {
                        Company = model.Company,
                        Email   = model.Email
                    });

                    //Assign to "User" Role
                    Roles.AddUserToRole(model.UserName, "User");

                    #region Messaging

                    //Extract current domain name:
                    string domainName = Request.UserHostName.ToString();

                    //Send email:
                    Messaging.MessagingService messaging = new Messaging.MessagingService();
                    string HtmlBody = "Please login with the information below, and test the logging system for Kaz by clicking on the testing link on the portal page. Thanks! <br/><hr/><br/>username: "******"<br/>" + "password: "******"<br/>" + "<a href='http://" + Request.Url.Host + "/'>LOGIN</a>";



                    await messaging.SendEmail(model.Email, ProjectSettings.Emails.NewUser_EmailSubjectLine, HtmlBody, ProjectSettings.Emails.NewUser_EmailFrom, ProjectSettings.Emails.NewUser_EmailFromName);

                    #endregion

                    #region Logging

                    UserProfile userProfile = await Sql.SelectStatements.GetUserProfileTask(WebSecurity.CurrentUserName);

                    LoggingDataService loggingDataService = new LoggingDataService();
                    string             description        = "New user created [UserName:"******", Email: " + model.Email + ", Company: " + model.Company + "]";
                    await loggingDataService.LogAsync(userProfile, LogTypes.Platform, PlatformTypes.UserCreated, description, Request);

                    #endregion

                    return(RedirectToAction("Index", "Users"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            }

            return(View(model));
        }
Beispiel #2
0
        public async Task<ActionResult> Create(UserProfile model)
        {
            //return View();

            if (ModelState.IsValid)
            {
                string autoGeneratedPassword = Membership.GeneratePassword(8, 2); 

                try
                {
                    //Create User
                    WebSecurity.CreateUserAndAccount(
                        model.UserName,
                        autoGeneratedPassword,
                        propertyValues: new {
                            Company = model.Company,
                            Email = model.Email
                        });

                    //Assign to "User" Role
                    Roles.AddUserToRole(model.UserName, "User");

                    #region Messaging

                    //Extract current domain name:
                    string domainName = Request.UserHostName.ToString();

                    //Send email:
                    Messaging.MessagingService messaging = new Messaging.MessagingService();
                    string HtmlBody = "Please login with the information below, and test the logging system for Kaz by clicking on the testing link on the portal page. Thanks! <br/><hr/><br/>username: "******"<br/>" + "password: "******"<br/>" + "<a href='http://" + Request.Url.Host + "/'>LOGIN</a>";

                        

                    await messaging.SendEmail(model.Email, ProjectSettings.Emails.NewUser_EmailSubjectLine, HtmlBody, ProjectSettings.Emails.NewUser_EmailFrom, ProjectSettings.Emails.NewUser_EmailFromName);

                    #endregion

                    #region Logging

                    UserProfile userProfile = await Sql.SelectStatements.GetUserProfileTask(WebSecurity.CurrentUserName);

                    LoggingDataService loggingDataService = new LoggingDataService();
                    string description = "New user created [UserName:"******", Email: " + model.Email + ", Company: " + model.Company + "]";
                    await loggingDataService.LogAsync(userProfile, LogTypes.Platform, PlatformTypes.UserCreated, description, Request);

                    #endregion

                    return RedirectToAction("Index", "Users");
                }
                catch (MembershipCreateUserException e)
                {
                      ModelState.AddModelError("", e.Message);
                }
            }

            return View(model);

        }