コード例 #1
0
        public ActionResult UploadImage()
        {
            HttpPostedFileBase file     = Request.Files[0];
            string             fileName = Path.GetFileName(file.FileName);
            string             fileext  = Path.GetExtension(fileName);
            string             dir      = "/UploadImage/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/";

            Directory.CreateDirectory(Path.GetDirectoryName(Server.MapPath(dir)));
            string fulldir = dir + MD5Helper.GenerateMD5(fileName) + fileext;

            file.SaveAs(Server.MapPath(fulldir));
            ImageModel imageModel = new ImageModel()
            {
                src   = fulldir,
                title = fileName
            };
            var jsondata = new
            {
                code = 0,
                msg  = string.Empty,
                data = imageModel
            };

            return(Json(jsondata));
        }
コード例 #2
0
ファイル: ResourceService.cs プロジェクト: qzfu/dams
        /// <summary>
        /// 校验是否登陆成功
        /// </summary>
        /// <returns></returns>
        public bool CheckRegistered()
        {
            using (var db = new EFDbContext())
            {
                var data = db.Catagorys.FirstOrDefault(x => x.Type == (int)EnumData.CatagoryType.Register);
                if (data == null)
                {
                    var registerCode = MD5Helper.GenerateMD5(RegistrationHelper.getRNum());
                    db.Catagorys.Add(new Catagorys
                    {
                        Type        = (int)EnumData.CatagoryType.Register,
                        ItemText    = registerCode,
                        ItemValue   = "0",
                        Remark      = "",
                        CreatedTime = DateTime.Now
                    });

                    db.SaveChanges();
                    return(false);
                }
                else
                {
                    if (MD5Helper.GenerateMD5(data.ItemValue) != data.ItemText || RegistrationHelper.getRNumWithDate(data.CreatedTime) != data.ItemValue)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }
コード例 #3
0
        public ActionResult AddUserInfo(UserInfo userInfo)
        {
            var nameList = UserInfoService.GetEntities(x => x.UserName == userInfo.UserName &&
                                                       x.DelFlag == 1);

            if (nameList.Count() > 0)
            {
                return(Json(new
                {
                    msg = "用户名已存在,换个吧~~",
                    code = Status.error
                }
                            , JsonRequestBehavior.AllowGet));
            }
            userInfo.SubTime = DateTime.Now;
            userInfo.DelFlag = 1;
            string userName = userInfo.UserName;
            string userPwd  = userInfo.UserPwd;
            string tempPwd  = $"{userName}{userPwd}";

            userInfo.UserName = userName;
            userInfo.UserPwd  = MD5Helper.GenerateMD5(tempPwd);
            userInfo.Remark   = userInfo.UserPwd;
            UserInfoService.Add(userInfo);
            var jsondata = new { Status.code };

            return(Json(jsondata, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
ファイル: ResourceService.cs プロジェクト: qzfu/dams
 /// <summary>
 /// 注册成功保存记录
 /// </summary>
 /// <returns></returns>
 public bool SaveRegister(string code, DateTime date)
 {
     using (var db = new EFDbContext())
     {
         var data = db.Catagorys.FirstOrDefault(x => x.Type == (int)EnumData.CatagoryType.Register);
         if (data == null)
         {
             var registerCode = MD5Helper.GenerateMD5(code);
             db.Catagorys.Add(new Catagorys
             {
                 Type        = (int)EnumData.CatagoryType.Register,
                 ItemText    = registerCode,
                 ItemValue   = code,
                 Remark      = "",
                 CreatedTime = date
             });
         }
         else
         {
             data.ItemText    = MD5Helper.GenerateMD5(code);
             data.ItemValue   = code;
             data.CreatedTime = date;
         }
         try
         {
             return(db.SaveChanges() > 0);
         }
         catch (DbEntityValidationException ex)
         {
             throw ex;
         }
     }
 }
コード例 #5
0
 public ActionResult LoginProcess()
 {
     #region 验证码
     string strcode     = Request["usercode"];
     string sessioncode = Session["Vcode"].ToString();
     if (string.IsNullOrEmpty(sessioncode) || strcode != sessioncode)
     {
         var data = new { msg = "验证码错误", code = 500 };
         return(Json(data, JsonRequestBehavior.AllowGet));
     }
     #endregion
     string name     = Request["username"].ToString();
     string pwd      = Request["userpwd"].ToString();
     string password = MD5Helper.GenerateMD5($"{name}{pwd}");
     var    userInfo = UserInfoService.GetEntities(u => u.UserName == name &&
                                                   u.UserPwd == password && u.DelFlag == 1).FirstOrDefault();
     if (userInfo == null)
     {
         var data = new{ msg = "用户名或密码错误", code = 501 };
         return(Json(data, JsonRequestBehavior.AllowGet));
     }
     else
     {
         //改用Redis+cookie
         string loginuserId = Guid.NewGuid().ToString();
         ////把用户id写入Redis
         int userid = userInfo.Id;
         ////Common.Cache.CacheHelper.AddCache(loginuserId, userid, DateTime.Now.AddMinutes(20));
         CacheHelper.CacheHelper.AddCache(loginuserId, userid, DateTime.Now.AddMinutes(20));
         ////往客户端写入cookie
         Response.Cookies["loginuserId"].Value = loginuserId;
         var data = new { code = 200 };
         return(Json(data, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #6
0
ファイル: ResourceService.cs プロジェクト: qzfu/dams
        /// <summary>
        /// 校验是否当前使用是否有效(未过试用期或注册过)
        /// </summary>
        /// <returns></returns>
        public bool CheckEffective()
        {
            using (var db = new EFDbContext())
            {
                var data = db.Catagorys.FirstOrDefault(x => x.Type == (int)EnumData.CatagoryType.Register);
                if (data == null)
                {
                    var registerCode = MD5Helper.GenerateMD5(RegistrationHelper.getRNum());
                    db.Catagorys.Add(new Catagorys
                    {
                        Type        = (int)EnumData.CatagoryType.Register,
                        ItemText    = registerCode,
                        ItemValue   = "0",
                        Remark      = "",
                        CreatedTime = DateTime.Now
                    });
                    db.SaveChanges();
                    return(false);
                }
                else
                {
                    if (MD5Helper.GenerateMD5(data.ItemValue) == data.ItemText && RegistrationHelper.getRNumWithDate(data.CreatedTime) == data.ItemValue)
                    {
                        return(true);
                    }

                    var date = db.Catagorys.FirstOrDefault(x => x.Type == (int)EnumData.CatagoryType.StartEnd);

                    if (date == null)
                    {
                        db.Catagorys.Add(new Catagorys
                        {
                            Type        = (int)EnumData.CatagoryType.StartEnd,
                            ItemText    = DateTime.Now.ToString("yyyy-MM-dd"),
                            ItemValue   = DateTime.Now.ToString("yyyy-MM-dd"),
                            Remark      = "",
                            CreatedTime = DateTime.Now
                        });
                        db.SaveChanges();
                        return(false);
                    }
                    else
                    {
                        var startDate = DateTime.Now.AddMonths(-1);
                        DateTime.TryParse(date.ItemValue, out startDate);

                        TimeSpan sp = DateTime.Today.Subtract(startDate);
                        if (sp.Days >= 7)
                        {
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                }
            }
        }
コード例 #7
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            this.btnLogin.Enabled = false;

            if (string.IsNullOrEmpty(cmbLoginID.Text))
            {
                ShowMessage("请输入用户名!", false);
                cmbLoginID.Focus();
                btnLogin.Enabled = true;
                return;
            }

            if (string.IsNullOrEmpty(txtPassword.Text))
            {
                ShowMessage("请输入密码!", false);
                txtPassword.Focus();
                btnLogin.Enabled = true;
                return;
            }

            ShowMessage("正在登录......");
            Thread.CurrentThread.Join(500);
            //DialogResult = DialogResult.OK;
            try
            {
                var loginId  = cmbLoginID.Text;
                var password = this.txtPassword.Text;
                var user     = userService.GetUserByUserId(loginId, MD5Helper.GenerateMD5(password));
                if (user == null)
                {
                    ShowMessage("用户名或密码不正确!");
                    this.btnLogin.Enabled = true;
                    return;
                }
                LoginUser.loginID     = this.cmbLoginID.Text;
                LoginUser.CurrentUser = user;
                if (!String.IsNullOrWhiteSpace(password))
                {
                    password = ckbSavePwd.IsChecked ? this.txtPassword.Text : String.Empty;//密码加密
                }

                SavePassword(this.cmbLoginID.Text, password);//保存登录账号和密码

                LoginID      = cmbLoginID.Text;
                PasswordText = txtPassword.Text;

                ShowMessage("已经完成登录认证......");

                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                SavePassword(this.cmbLoginID.Text, String.Empty, false);//保存登录账号和密码
            }

            btnLogin.Enabled = true;
        }
コード例 #8
0
ファイル: LoginDao.cs プロジェクト: changge666/github_weiqi
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public ReResult to_Login(string data)
        {
            var rec = new Record(data);

            if (rec.GetString("user_name").IsBlank())
            {
                re.Code    = 500;
                re.Message = "账号未输入";
            }
            else if (rec.GetString("user_pass").IsBlank())
            {
                re.Code    = 500;
                re.Message = "密码未输入";
            }
            else if (rec.GetString("pic").IsBlank())
            {
                re.Code    = 500;
                re.Message = "验证码未输入";
            }
            else if (rec.GetString("pic1").IsBlank())
            {
                re.Code    = 500;
                re.Message = "验证码已过时,请刷新";
            }
            else if (!rec.GetString("pic").Equals(rec.GetString("pic1")))
            {
                re.Code    = 500;
                re.Message = "验证码错误";
            }
            else if (rec.GetString("user_name").IsBlank() || rec.GetString("user_pass").IsBlank())
            {
                re.Code    = 500;
                re.Message = "登陆信息不全";
            }
            else
            {
                rec["password"] = MD5Helper.GenerateMD5(rec.GetString("user_pass"));
                rec.Remove("pic");
                rec.Remove("pic1");
                var t = QueryAction.GetRecord("user_table", rec);
                if (t.IsBlank())
                {
                    re.Code    = 500;
                    re.Message = "登陆信息错误";
                }
                else
                {
                    re.Message = LoginCurrent.Login(t).token;
                }
            }
            return(re);
        }
コード例 #9
0
ファイル: ResourceService.cs プロジェクト: qzfu/dams
        /// <summary>
        /// 保存第一次登陆时间,和注册状态
        /// </summary>
        public void SetStartDate()
        {
            using (var db = new EFDbContext())
            {
                var data = db.Catagorys.FirstOrDefault(x => x.Type == (int)EnumData.CatagoryType.StartEnd);
                if (data == null)
                {
                    db.Catagorys.Add(new Catagorys
                    {
                        Type        = (int)EnumData.CatagoryType.StartEnd,
                        ItemText    = DateTime.Now.ToString("yyyy-MM-dd"),
                        ItemValue   = DateTime.Now.ToString("yyyy-MM-dd"),
                        Remark      = "",
                        CreatedTime = DateTime.Now
                    });
                    db.SaveChanges();
                }

                data = db.Catagorys.FirstOrDefault(x => x.Type == (int)EnumData.CatagoryType.Register);
                var registerCode = MD5Helper.GenerateMD5(RegistrationHelper.getRNum());
                if (data == null)
                {
                    db.Catagorys.Add(new Catagorys
                    {
                        Type        = (int)EnumData.CatagoryType.Register,
                        ItemText    = registerCode,
                        ItemValue   = "0",
                        Remark      = "",
                        CreatedTime = DateTime.Now
                    });
                    db.SaveChanges();
                }
                else
                {
                    if (data.ItemText == "0" || data.ItemText == "1")
                    {
                        data.ItemText = registerCode;
                        db.SaveChanges();
                    }
                }
            }
        }
コード例 #10
0
ファイル: UserInfoControl.cs プロジェクト: qzfu/dams
        private bool SaveNewPassWord()
        {
            this.Warn1label.Visible = false;
            this.Warn2label.Visible = false;
            this.Warn3label.Visible = false;

            var userId = this.UserIdTextBox.Text;
            var oldpw  = this.OldPWTextBox.Text;
            var newpw  = this.NewPWTextBox.Text;
            var newpw2 = this.NewPW2TextBox.Text;

            var flag = false;

            if (string.IsNullOrEmpty(oldpw))
            {
                flag = true;
                this.Warn1label.Text    = "*请输入旧密码";
                this.Warn1label.Visible = true;
            }
            if (string.IsNullOrEmpty(newpw))
            {
                flag = true;
                this.Warn3label.Text    = "*请输入新密码";
                this.Warn3label.Visible = true;
            }
            if (string.IsNullOrEmpty(newpw2))
            {
                flag = true;
                this.Warn2label.Text    = "*请再次输入新密码";
                this.Warn2label.Visible = true;
            }
            if (flag)
            {
                return(false);
            }

            var user = userService.GetUserByUserId(userId, MD5Helper.GenerateMD5(oldpw));

            if (user == null)
            {
                this.Warn1label.Text    = "*旧密码输入不正确";
                this.Warn1label.Visible = true;
                return(false);
            }

            if (newpw != newpw2)
            {
                this.Warn2label.Text    = "*新密码输入不一致";
                this.Warn2label.Visible = true;
                return(false);
            }

            var result = userService.SaveChangePassword(userId, MD5Helper.GenerateMD5(newpw));

            if (result)
            {
                MessageBox.Show("密码修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("密码修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }
コード例 #11
0
ファイル: UserProfile.cs プロジェクト: showous/amusinghoS
 public UserProfile()
 {
     CreateMap <UserViewModel, amusingUser>()
     .ForMember(desc => desc.password, opt => opt.MapFrom(src => MD5Helper.GenerateMD5(src.password)))
     .ForMember(desc => desc.articleUserName, opt => opt.MapFrom(src => src.username));
 }