Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "UserId,Name,Email,Password,Type")] User user)
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else if (Session["UserType"].ToString() != UserType.Administrator.ToString() && Session["UserType"].ToString() != UserType.Coordinator.ToString())
            {
                TempData["msg"] = "You don't have enough rights";
                return(RedirectToAction("Login", "Home"));
            }
            if (ModelState.IsValid)
            {
                var ExistingUser = db.Users.Where(s => s.Email.Equals(user.Email, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                if (ExistingUser != null)
                {
                    TempData["msg"] = "Email already registered!";
                    return(View(user));
                }

                TempData["msg"] = "New User Added";
                user.Password   = MD5Hasher.Encrypt(user.Password, "vgrad");
                db.Users.Add(user);
                db.SaveChanges();
                TempData["msg"] = "User Created";
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Ejemplo n.º 2
0
        public ActionResult Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                var password = MD5Hasher.Encrypt(model.password, "vgrad");
                var user     = db.Users.Where(s => s.Email.Equals(model.Email, StringComparison.CurrentCultureIgnoreCase) && s.Password == password).FirstOrDefault();
                if (user == null)
                {
                    TempData["msg"] = "Invalid Email/Password!";
                    return(View(model));
                }
                Session["UserName"] = user.Name;
                Session["UserType"] = user.Type;
                Session["UserId"]   = user.UserId;
                Session["Email"]    = user.Email;
                switch (user.Type)
                {
                case UserType.Administrator:
                    return(RedirectToAction("Index", "Users"));

                case UserType.Coordinator:
                    return(RedirectToAction("Index", "Projects"));

                case UserType.Student:
                    return(RedirectToAction("BasicInformation", "Home"));

                default:
                    return(RedirectToAction(""));
                }
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult Edit([Bind(Include = "UserId,Name,Email,Password,Type")] User user)
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else if (Session["UserType"].ToString() != UserType.Administrator.ToString() && Session["UserType"].ToString() != UserType.Coordinator.ToString())
            {
                TempData["msg"] = "You don't have enough rights";
                return(RedirectToAction("Login", "Home"));
            }
            if (ModelState.IsValid)
            {
                var userWithEmail = db.Users.Where(s => s.Email.Equals(user.Email, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                if (userWithEmail != null && userWithEmail.UserId != user.UserId)
                {
                    TempData["msg"] = "Email already registered to another user";
                    return(View(user));
                }

                user.Password = MD5Hasher.Encrypt(user.Password, "vgrad");
                var usr     = db.Users.Where(s => s.UserId == user.UserId).FirstOrDefault();
                var student = db.Students.Where(s => s.StudentId == user.UserId).FirstOrDefault();
                if (student != null)
                {
                    if (usr.Type == UserType.Student && user.Type != UserType.Student)
                    {
                        TempData["msg"] = "Please delete corresponding student details first from student tab";
                        return(RedirectToAction("Index", "Users"));
                    }
                }



                usr.Name     = user.Name;
                usr.Email    = user.Email;
                usr.Password = user.Password;
                usr.Type     = user.Type;

                TempData["msg"] = "User Updated Successfully";
                //db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
Ejemplo n.º 4
0
 public ActionResult CreateNew(User model)
 {
     if (ModelState.IsValid)
     {
         var password = MD5Hasher.Encrypt(model.Password, "vgrad");
         var user     = db.Users.Where(s => s.Email.Equals(model.Email, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
         if (user != null)
         {
             TempData["msg"] = "Email Address already exists, try new.";
             return(View(model));
         }
         model.Password = password;
         //model.Type = mode;
         model.Status = false;
         db.Users.Add(model);
         db.SaveChanges();
         return(Json("UserCreated", JsonRequestBehavior.AllowGet));
     }
     return(Json("Error Creating User", JsonRequestBehavior.AllowGet));
 }
Ejemplo n.º 5
0
 public ActionResult SignUp(User model)
 {
     if (ModelState.IsValid)
     {
         var password = MD5Hasher.Encrypt(model.Password, "vgrad");
         var user     = db.Users.Where(s => s.Email.Equals(model.Email, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
         if (user != null)
         {
             TempData["msg"] = "Email Address already exists, try new.";
             return(View(model));
         }
         model.Password = password;
         model.Type     = UserType.Student;
         model.Status   = false;
         db.Users.Add(model);
         db.SaveChanges();
         TempData["msg"] = "Signup successfull but needs co-ordinator attention to assign any other role.";
         return(RedirectToAction("Login", "Home"));
     }
     return(View(model));
 }