示例#1
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));
        }
示例#2
0
        public async Task <ActionResult> Login(LoginModel login)
        {
            if (ModelState.IsValid)
            {
                if (WebSecurity.Login(login.UserName, login.Password, true))
                {
                    if (Roles.IsUserInRole(login.UserName, "Admin"))
                    {
                        return(RedirectToAction("Index", "Admin"));
                    }

                    UserProfile userProfile = await Sql.SelectStatements.GetUserProfileTask(login.UserName);

                    #region Logging

                    LoggingDataService loggingDataService = new LoggingDataService();
                    string             description        = userProfile.UserName + " has logged into the system";;
                    await loggingDataService.LogAsync(userProfile, LogTypes.Activity, ActivityTypes.Login, description, Request);

                    #endregion

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(login));
                }
            }

            return(View(login));
        }
示例#3
0
        public async Task <ActionResult> LogError()
        {
            UserProfile userProfile = await Sql.SelectStatements.GetUserProfileTask(WebSecurity.CurrentUserName);

            LoggingDataService loggingDataService = new LoggingDataService();
            string             description        = "Test error logged by the 'LogError' Controller";
            await loggingDataService.LogAsync(userProfile, LogTypes.Error, ErrorTypes.Exception, description, Request);

            return(Content("Test error logged"));
        }
示例#4
0
        public async Task <ActionResult> LogDownload()
        {
            #region Logging

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

            LoggingDataService loggingDataService = new LoggingDataService();
            string             description        = "xyz.psd"; //<---filename
            await loggingDataService.LogAsync(userProfile, LogTypes.Activity, ActivityTypes.Download, description, Request);

            #endregion

            return(Content("Your activity has been logged as a 'download' by the user: '******' at: " + TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.ToUniversalTime(), TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"))));
        }