Пример #1
0
        public ActionResult Login(LoginModel model)
        {
            var url = Request.Url;

            if (ModelState.IsValid)
            {
                if (model.Username != null && model.Password != null)
                {
                    //string verifier = Crypto.Hash(model.Password,"sha256").Remove(32);
                    string  verifier  = UtilitiesHelper.Encrypt(model.Password);
                    rs_user loginUser = db.rs_user.FirstOrDefault(m => m.Username == model.Username && m.Password == verifier && m.FlagActive == true && m.IsBackEnd == true);
                    if (loginUser != null)
                    {
                        //FormsAuthentication.SetAuthCookie(loginUser.Username, false);

                        string userData = (loginUser.GroupId == null) ? "0" : loginUser.GroupId.ToString();

                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                                                                                         loginUser.Username,
                                                                                         DateTime.Now,
                                                                                         DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes),
                                                                                         false,
                                                                                         userData);

                        // Encrypt the ticket.
                        string encTicket = FormsAuthentication.Encrypt(ticket);

                        // Create the cookie.
                        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                        //FormsAuthentication.SetAuthCookie(model.Username, true);
                        Logger.Username = model.Username;
                        Logger.Log("Login", "Logged in with user [" + model.Username + "]");

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        Logger.Username = model.Username;
                        Logger.Log("Login", "Failed to login, user [" + model.Username + "]");
                        TempData["Notification"] = NotificationHelper.Error("Username and Password is incorrect");
                    }
                }
                else
                {
                    TempData["Notification"] = NotificationHelper.Warning("Please provide correct Username and Password");
                }
            }

            return(View(model));
        }
Пример #2
0
        public ActionResult Create(rs_user rs_user)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                if (ModelState.IsValid)
                {
                    rs_user current = db.rs_user.SingleOrDefault(m => m.Username == rs_user.Username);
                    if (current != null)
                    {
                        TempData["Notification"] = NotificationHelper.Error("Username '" + rs_user.Username + "' already exist.");
                    }
                    else
                    {
                        try
                        {
                            rs_user.Password  = UtilitiesHelper.Encrypt(rs_user.Password);
                            rs_user.IsBackEnd = true;
                            rs_user.UserEntry = User.Identity.Name;
                            rs_user.DateEntry = DateTime.Now;

                            db.rs_user.Add(rs_user);
                            db.SaveChanges();

                            Logger.Log("Add", "New User [Username: "******"]");

                            TempData["Notification"] = NotificationHelper.Inform("New User [Username: "******"]");
                            return(RedirectToAction("Index"));
                        }
                        catch (Exception ex)
                        {
                            TempData["Notification"] = NotificationHelper.Error(ex.Message);
                        }
                    }
                }

                //ViewBag.CompanyId = new SelectList(db.rs_company.Where(c => c.FlagActive == true).OrderBy(c => c.Name), "CompanyId", "Name", rs_user.CompanyId);
                ViewBag.GroupId = new SelectList(db.rs_user_group.Where(g => g.FlagActive == true).OrderBy(g => g.Name), "GroupId", "Name", rs_user.GroupId);

                return(View(rs_user));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
        public void TestMethod1()
        {
            ChromeOptions options = new ChromeOptions();

            driver = new ChromeDriver("C:\\Users\\pavan.gundapanthula\\source\\repos\\SeleniumDemo", options);
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://www.google.com/gmail/about/#");
            UtilitiesHelper.Neu_GenericTestStepRecorder(true, "Navigation to the Gmail about sccreen is successful.");
            driver.Neu_TakeScreenShotExtension("Gmail About Screen");
            driver.FindElement(By.XPath("//*[@class='h-c-header__nav-li g-mail-nav-links']//child::a[contains(text(),'Sign in')]")).Click();
            UtilitiesHelper.Neu_SwitchWindow(driver, "Gmail");
            UtilitiesHelper.Neu_GenericTestStepRecorder(true, "Navigation to the Gmail Login sccreen is successful.");
            driver.Neu_TakeScreenShotExtension("User Name Screen");
            driver.FindElement(By.Id("identifierId")).SendKeys("Neudesic983");
            UtilitiesHelper.Neu_GenericTestStepRecorder(true, "Entered the username successfully.");
            driver.Neu_TakeScreenShotExtension("User Name Entered");
            driver.FindElement(By.Id("identifierNext")).Click();
            UtilitiesHelper.Neu_GenericTestStepRecorder(true, "Clicked on Next Button.");
            driver.Neu_TakeScreenShotExtension("Password Screen");
            driver.FindElement(By.Name("password")).SendKeys("Neudesic@123");
            UtilitiesHelper.Neu_GenericTestStepRecorder(true, "Entered the password successfully.");
            driver.Neu_TakeScreenShotExtension("Password Entered Screen");
            driver.FindElement(By.Id("passwordNext")).Click();
            UtilitiesHelper.Neu_GenericTestStepRecorder(true, "Clicked on Sign In Button.");
            driver.Neu_TakeScreenShotExtension("Gmail Landing Screen");

            Thread.Sleep(5000);

            driver.FindElement(By.XPath("//*[text()='Compose']")).Neu_WaitForControlReady(driver, 5000);
            driver.FindElement(By.XPath("//*[text()='Compose']")).Click();
            driver.FindElement(By.XPath("//textarea[@name='to']")).Neu_WaitForControlReady(driver, 5000);
            driver.FindElement(By.XPath("//textarea[@name='to']")).SendKeys("*****@*****.**");
            driver.FindElement(By.XPath("//input[@name='subjectbox']")).SendKeys("Testing Mail @ " + DateTime.Now);
            driver.FindElement(By.XPath("//*[text()='Send']//ancestor::div[3]//descendant::div[19]")).Click();

            #region Handle Windows Controls here
            // Write your logic to upload a file......

            #endregion

            Thread.Sleep(10000);
            driver.FindElement(By.XPath("//*[text()='Send']")).Click();
            Thread.Sleep(10000);
            driver.Quit();
        }
Пример #4
0
        private void ValidateUser(UserInfo userInfo)
        {
            if (string.IsNullOrWhiteSpace(userInfo.FirstName))
            {
                throw new CcsSsoException("ERROR_FIRSTNAME_REQUIRED");
            }

            if (string.IsNullOrWhiteSpace(userInfo.LastName))
            {
                throw new CcsSsoException("ERROR_LASTNAME_REQUIRED");
            }

            if (string.IsNullOrWhiteSpace(userInfo.Email))
            {
                throw new CcsSsoException("ERROR_EMAIL_REQUIRED");
            }

            if (!UtilitiesHelper.IsEmailValid(userInfo.Email))
            {
                throw new CcsSsoException("ERROR_EMAIL_FORMAT");
            }
        }
        public ActionResult Index(ChangePasswordModel cp)
        {
            rs_user rs_user = new rs_user();

            try
            {
                string CurrentPassword = db.rs_user.Where(m => m.Username == User.Identity.Name).Single().Password;
                if (ModelState.IsValid)
                {
                    //if (Crypto.Hash(cp.OldPassword).Remove(32) == CurrentPassword)
                    if (UtilitiesHelper.Encrypt(cp.OldPassword) == CurrentPassword)
                    {
                        rs_user baru = new rs_user();
                        baru = db.rs_user.Where(m => m.Username == User.Identity.Name).Single();

                        //baru.Password = Crypto.Hash(cp.NewPassword).Remove(32);
                        baru.Password = UtilitiesHelper.Encrypt(cp.NewPassword);


                        db.Entry(baru).State = EntityState.Modified;
                        db.SaveChanges();

                        Logger.Log("Change Password", "User Change Password [" + baru.Username + "]");

                        TempData["Notification"] = NotificationHelper.Inform("You have successfully changed your password.");
                    }
                    else
                    {
                        TempData["Notification"] = NotificationHelper.Error("Incorrect old password!");
                    }
                }
            }
            catch (Exception)
            {
                TempData["Notification"] = NotificationHelper.Error("Change password failed!");
            }

            return(View(cp));
        }
Пример #6
0
        public ActionResult Reset(rs_user rs_user)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                try
                {
                    rs_user baru = new rs_user();
                    baru = db.rs_user.Where(m => m.UserId == rs_user.UserId).Single();

                    //baru.Password = Crypto.Hash("123456", "sha256").Remove(32);
                    baru.Password   = UtilitiesHelper.Encrypt("123456");
                    baru.UserUpdate = User.Identity.Name;
                    baru.DateUpdate = DateTime.Now;

                    db.Entry(baru).State = EntityState.Modified;
                    db.SaveChanges();
                    //db.rs_user.ApplyCurrentValues(baru);
                    //db.SaveChanges();
                    //db.rs_user.Attach(baru);
                    //db.ObjectStateManager.ChangeObjectState(baru, EntityState.Modified);
                    //db.SaveChanges();

                    Logger.Log("Reset", "Reset User Password [Username:"******"]");

                    TempData["Notification"] = NotificationHelper.Inform("Reset User Password [Username:"******"]");
                }
                catch (Exception ex)
                {
                    TempData["Notification"] = NotificationHelper.Error(ex.Message);
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
Пример #7
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                if (file != null && file.ContentLength > 0)
                {
                    if (Path.GetExtension(file.FileName).ToLower() != ".xls")
                    {
                        TempData["Notification"] = NotificationHelper.Error("Only XLS files are supported.");
                    }
                    else
                    {
                        try
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var path     = Path.Combine(Server.MapPath("~/Content/Uploads"), fileName);
                            file.SaveAs(path);

                            DateTime         start_time = DateTime.Now;
                            ParserInfoHelper PI_Helper  = new ParserInfoHelper();
                            int    recordProcessed      = 0;
                            int    recordWarning        = 0;
                            int    recordInserted       = 0;
                            int    recordError          = 0;
                            string Summary = string.Empty;

                            Summary += "Filename : " + fileName + "<br><br>";

                            ExcelHelper helper = new ExcelHelper();
                            ArrayList   data   = helper.Parser(path, new String[] { "User", "1", "1", User.Identity.Name, DateTime.Now.ToString("dd-mm-yyyy HH:mm:ss") }, "Sheet1");

                            foreach (ArrayList row in data)
                            {
                                row[1] = UtilitiesHelper.Encrypt(row[1].ToString());
                            }

                            int totalRows = data.Count;

                            if (totalRows > 0)
                            {
                                helper.RowProcessed += (s, t) => recordProcessed += 1;
                                helper.RowInserted  += (s, t) =>
                                {
                                    recordInserted += 1;
                                    PI_Helper.AddInfo(t.Message);
                                };
                                helper.RowWarning += (s, t) =>
                                {
                                    recordWarning += 1;
                                    PI_Helper.AddWarning(t.Message);
                                };
                                helper.RowError += (s, t) =>
                                {
                                    recordError += 1;
                                    PI_Helper.AddError(t.Message);
                                };

                                helper.Import(data, "rs_user", new string[] { "Username", "Password", "FullName", "UserType", "IsBackEnd", "FlagActive", "UserEntry", "DateEntry" }, null, new List <string>(new string[] { "1" }));
                            }

                            Summary          += "Record Processed : " + recordProcessed + "<br>";
                            Summary          += "Record Inserted : " + recordInserted + "<br>";
                            Summary          += "Record Error : " + recordError + "<br>";
                            Summary          += "Record Warning : " + recordWarning + "<br><br>";
                            Summary          += "Elapsed Time: " + DateTime.Now.Subtract(start_time).Minutes + " minutes";
                            PI_Helper.Summary = Summary;

                            Logger.Log("Upload", "User upload successful.");

                            TempData["Notification"] = PI_Helper.Display();

                            return(RedirectToAction("Index"));
                        }
                        catch (Exception ex)
                        {
                            TempData["Notification"] = NotificationHelper.Error(ex.Message);
                        }
                    }
                }
                else
                {
                    TempData["Notification"] = NotificationHelper.Error("No file is selected.");
                }

                return(View());
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }