예제 #1
0
 public ActionResult Sign(Users user)
 {
     if (user != null)
     {
         int count = (from u in db.Users where u.UserName == user.UserName || u.Email == user.Email select u).Count();
         if (count == 0)
         {
             if (user.UserName.ToLower().Equals("admin"))
             {
                 user.Roles = UserBLL.Admin;
             }
             else
             {
                 user.Roles = UserBLL.Normal;
             }
             user.Password = UserBLL.MD5Hash(user.Password);
             user.Birthday = "1990-01-01";
             db.Users.Add(user);
             if (db.SaveChanges() > 0)
             {
                 return(Content(MoviesBLL.AlertAndRedirect("/Login", "注册成功!")));
             }
             else
             {
                 ViewBag.Message = "注册失败";
             }
         }
         else
         {
             ViewBag.Message = "用户名或邮箱账号已存在";
         }
     }
     return(View(user));
 }
예제 #2
0
        public ActionResult Portrait(string backUrl)
        {
            string path = Request.PhysicalApplicationPath + "portrait";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            HttpPostedFileBase file = Request.Files["myfile"];
            string             type = Path.GetExtension(file.FileName).ToLower();

            if ((type.Equals(".jpg") || type.Equals(".png") || type.Equals(".jpeg") || type.Equals(".gif")) && file.ContentLength <= 3145728)
            {
                Image  img    = Image.FromStream(file.InputStream);
                int    max    = img.Width < img.Height ? img.Width : img.Height;
                int    maxPix = 200;//设定最大像素
                string src    = "temp" + DateTime.Now.ToString("yyyyMMddHHmmss") + type;

                /*if (max > maxPix)注释此代码,可将大图片变小,小图片变大
                 * {*/
                int width, height;
                width  = img.Width;
                height = img.Height;
                float scale = ((float)max / (float)maxPix);
                if (width < height)
                {
                    width  = maxPix;
                    height = (int)(height / scale);
                }
                else
                {
                    height = maxPix;
                    width  = (int)(width / scale);
                }
                Image newImg = new Bitmap(img, width, height);
                newImg.Save(path + "\\" + src, img.RawFormat);

                /*}
                 * else
                 *  file.SaveAs(path + "\\" + src);*/
                ViewData.Add("imgresouce", "/portrait/" + src);
                Session["tempPath"] = path;
                Session["tempSrc"]  = src;
                Session["backUrl"]  = backUrl;
                return(View());
            }
            else
            {
                return(Content(MoviesBLL.AlertAndRedirect(backUrl, "请上传小于3MB的图片文件!")));
            }
        }
예제 #3
0
        public ActionResult ChangePassword(FormCollection form)
        {
            Users user = UserBLL.getLoginUser(this);

            if (user != null)
            {
                string old   = form["oldpass"];
                string pass1 = form["password"];
                string pass2 = form["password2"];
                if (pass1.Equals(pass2))
                {
                    if (UserBLL.MD5Hash(old).Equals(user.Password))
                    {
                        Users newUser = db.Users.Find(user.ID);
                        newUser.Password = UserBLL.MD5Hash(pass2);
                        db.Entry <Users>(newUser).State = System.Data.Entity.EntityState.Modified;
                        if (db.SaveChanges() > 0)
                        {
                            UserBLL.Login(this, newUser);
                            return(Content(MoviesBLL.AlertAndRedirect("/Index", "修改成功")));
                        }
                        else
                        {
                            ViewBag.Message = "修改失败";
                        }
                    }
                    else
                    {
                        ViewBag.Message = "原密码输入不正确";
                    }
                }
                else
                {
                    ViewBag.Message = "两次输入的密码不一致";
                }
            }
            return(View());
        }