Пример #1
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);
        }
Пример #2
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");
        }
Пример #3
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")));
        }
Пример #4
0
        public async Task<bool> LogAsync(UserProfile userProfile, string logType, string logSubType, string description, HttpRequestBase request)
        {
                LogItem logItem = new LogItem();

                logItem.LogType = logType;
                logItem.LogSubtype = logSubType;
                logItem.Company = userProfile.Company;
                logItem.UserName = userProfile.UserName;
                logItem.Email = userProfile.Email;
                logItem.Description = description;

                try
                {
                    logItem.IPAddress = (request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim().Split(':')[0].ToString();
                }
                catch
                {
                    logItem.IPAddress = "null";
                }

                LoggingDataService loggingDataService = new LoggingDataService();

                return await loggingDataService.LogItemAsync(logItem);
        }
Пример #5
0
        public async Task <bool> LogAsync(UserProfile userProfile, string logType, string logSubType, string description, HttpRequestBase request)
        {
            LogItem logItem = new LogItem();

            logItem.LogType     = logType;
            logItem.LogSubtype  = logSubType;
            logItem.Company     = userProfile.Company;
            logItem.UserName    = userProfile.UserName;
            logItem.Email       = userProfile.Email;
            logItem.Description = description;

            try
            {
                logItem.IPAddress = (request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim().Split(':')[0].ToString();
            }
            catch
            {
                logItem.IPAddress = "null";
            }

            LoggingDataService loggingDataService = new LoggingDataService();

            return(await loggingDataService.LogItemAsync(logItem));
        }
Пример #6
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);

        }