Esempio n. 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                try
                {
                    rs_user rs_user = db.rs_user.Single(s => s.UserId == id);

                    Logger.Log("Delete", "Delete User [ID:" + rs_user.UserId + "Username:"******"]");
                    TempData["Notification"] = NotificationHelper.Inform("Delete User [ID:" + rs_user.UserId + ", Username:"******"]");

                    db.rs_user.Remove(rs_user);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    TempData["Notification"] = NotificationHelper.Error(ex.Message);
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            rs_user rs_user = db.rs_user.Find(id);

            db.rs_user.Remove(rs_user);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
 public ActionResult Edit([Bind(Include = "UserId,Username,Password,FullName,MobileNumber,Email,CompanyId,GroupId,UserType,IsBackEnd,FlagActive,UserEntry,DateEntry,UserUpdate,DateUpdate,Department")] rs_user rs_user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rs_user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     //ViewBag.CompanyId = new SelectList(db.rs_company, "CompanyId", "CompanyCode", rs_user.CompanyId);
     ViewBag.GroupId = new SelectList(db.rs_user_group, "GroupId", "Name", rs_user.GroupId);
     return(View(rs_user));
 }
Esempio n. 4
0
        //
        // GET: /User/Delete/5

        public ActionResult Delete(int id)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                rs_user rs_user = db.rs_user.Single(s => s.UserId == id);
                return(View(rs_user));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
Esempio n. 5
0
        // GET: Users/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            rs_user rs_user = db.rs_user.Find(id);

            if (rs_user == null)
            {
                return(HttpNotFound());
            }
            return(View(rs_user));
        }
Esempio n. 6
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));
        }
Esempio n. 7
0
        //
        // GET: /User/Edit/5

        public ActionResult Edit(int id)
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                rs_user rs_user = db.rs_user.Single(s => s.UserId == id);
                //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"));
            }
        }
Esempio n. 8
0
        // GET: Users/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            rs_user rs_user = db.rs_user.Find(id);

            if (rs_user == null)
            {
                return(HttpNotFound());
            }
            //ViewBag.CompanyId = new SelectList(db.rs_company, "CompanyId", "CompanyCode", rs_user.CompanyId);
            ViewBag.GroupId = new SelectList(db.rs_user_group, "GroupId", "Name", rs_user.GroupId);
            return(View(rs_user));
        }
Esempio n. 9
0
        //
        // GET: /User/Create

        public ActionResult Create()
        {
            if (AclHelper.hasAccess(User, currentAction, currentController))
            {
                //ViewBag.CompanyId = new SelectList(db.rs_company.Where(c => c.FlagActive == true).OrderBy(c => c.Name), "CompanyId", "Name");
                ViewBag.GroupId = new SelectList(db.rs_user_group.Where(g => g.FlagActive == true).OrderBy(g => g.Name), "GroupId", "Name");
                //ViewBag.UserEntry = new SelectList(db.rs_user, "UserId", "Username");
                //ViewBag.UserUpdate = new SelectList(db.rs_user, "UserId", "Username");
                rs_user user = new rs_user();
                user.UserType = UserType;
                return(View(user));
            }
            else
            {
                return(RedirectToAction("NotAuthenticated", "Home"));
            }
        }
Esempio n. 10
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 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));
        }
Esempio n. 12
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"));
            }
        }