public ActionResult Index(Models.adminModel admin, string returnUrl)
        {
            if (admin.username != null && admin.password != null)
            {
                if (isValid(admin.username, admin.password))
                {
                    Roles.GetRolesForUser();
                    FormsAuthentication.SetAuthCookie(admin.username, false);

                    if (returnUrl != null)
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "content"));
                    }
                }
                else
                {
                    ViewBag.error = 'y';
                }
            }
            return(View(admin));
        }
        public ActionResult Registration(Models.adminModel admin)
        {
            if (ModelState.IsValid)
            {
                if (admin.password == admin.retype_password)
                {
                    var user = db.users.FirstOrDefault(u => u.username == admin.username);
                    if (user == null)
                    {
                        using (db)
                        {
                            var crypto         = new SimpleCrypto.PBKDF2();
                            var enkripPassword = crypto.Compute(admin.password);
                            var create         = db.users.Create();
                            var roles          = db.detail_roles.Create();

                            create.username          = admin.username;
                            create.user_password     = enkripPassword;
                            create.user_passwordsalt = crypto.Salt;
                            create.nama    = admin.nama;
                            create.hp      = admin.hp;
                            create.email   = admin.email;
                            create.alamat  = admin.alamat;
                            create.tanggal = DateTime.Now;

                            db.users.Add(create);
                            db.SaveChanges();

                            roles.id_roles = admin.id_roles;
                            roles.id_user  = (from table in db.users where table.username == admin.username select table.id_user).FirstOrDefault();

                            db.detail_roles.Add(roles);
                            db.SaveChanges();

                            return(RedirectToAction("Index", "admin"));
                        }
                    }
                    else
                    {
                        ViewBag.role          = new SelectList(db.roles.ToList(), "id_roles", "roles");
                        ViewBag.errorUsername = '******';
                        return(View(admin));
                    }
                }
                else
                {
                    ViewBag.role          = new SelectList(db.roles.ToList(), "id_roles", "roles");
                    ViewBag.errorPassword = '******';
                    return(View(admin));
                }
            }
            else
            {
                ViewBag.role  = new SelectList(db.roles.ToList(), "id_roles", "roles");
                ViewBag.error = 'y';
                return(View(admin));
            }
        }
Example #3
0
        public ActionResult EditUser(int id, Models.adminModel admin)
        {
            if (ModelState.IsValid)
            {
                if (admin.password == admin.retype_password)
                {
                    var          userUbah     = db.users.FirstOrDefault(u => u.username == admin.username);
                    var          idRole       = db.detail_roles.FirstOrDefault(u => u.id_user == id).id_detail_roles;
                    detail_roles detail_roles = db.detail_roles.Find(idRole);
                    if (userUbah == null)
                    {
                        user user = db.users.Find(id);
                        using (db)
                        {
                            var crypto         = new SimpleCrypto.PBKDF2();
                            var enkripPassword = crypto.Compute(admin.password);

                            user.username          = admin.username;
                            user.user_password     = enkripPassword;
                            user.user_passwordsalt = crypto.Salt;
                            user.nama    = admin.nama;
                            user.hp      = admin.hp;
                            user.email   = admin.email;
                            user.alamat  = admin.alamat;
                            user.tanggal = DateTime.Now;

                            detail_roles.id_roles = id;
                            detail_roles.id_roles = admin.id_roles;

                            db.SaveChanges();

                            return(RedirectToAction("Index", "user"));
                        }
                    }
                    else
                    {
                        ViewBag.role          = new SelectList(db.roles.ToList(), "id_roles", "roles");
                        ViewBag.errorUsername = '******';
                        return(View(admin));
                    }
                }
                else
                {
                    ViewBag.role          = new SelectList(db.roles.ToList(), "id_roles", "roles");
                    ViewBag.errorPassword = '******';
                    return(View(admin));
                }
            }
            else
            {
                ViewBag.role  = new SelectList(db.roles.ToList(), "id_roles", "roles");
                ViewBag.error = 'y';
                return(View(admin));
            }
        }