Esempio n. 1
0
        public static OperateResult  ModifyPasswd(long id, string pwdOld, string pwd)
        {
            try
            {
                using (SystemDB db = new SystemDB())
                {
                    var element = (from m in db.userList
                                   where id == m.id
                                   select m
                                   ).FirstOrDefault();

                    if (element == null)
                    {
                        return(new OperateResult
                        {
                            content = "访问错误",
                        });
                    }

                    if (element.passwd != MD5Encode.Encode16(pwdOld))
                    {
                        return(new OperateResult
                        {
                            content = "原密码错误",
                        });
                    }


                    element.passwd = MD5Encode.Encode16(pwd);

                    db.Entry(element).State = System.Data.Entity.EntityState.Modified;

                    db.SaveChanges();

                    LogManager.Add(new LogRecord
                    {
                        userId  = SessionHelper.GetUserId(),
                        time    = DateTime.Now,
                        type    = "Info",
                        content = "重置密码:" + element.name
                    });


                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                        content = "更新成功"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new OperateResult
                {
                    content = Model.Utility.Utility.GetExceptionMsg(ex),
                });
            }
        }
Esempio n. 2
0
        public OperateResult Add(User model)
        {
            using (SystemDB db = new SystemDB())
            {
                try
                {
                    var match = from m in db.userList
                                where m.name.Equals(model.name)
                                select m;
                    if (match.Count() > 0)
                    {
                        return(new OperateResult
                        {
                            content = "用户已经存在",
                        });
                    }

                    model.passwd = MD5Encode.Encode16(model.passwd);

                    db.userList.Add(model);
                    db.SaveChanges();

                    LogManager.Add(new LogRecord
                    {
                        userId  = SessionHelper.GetUserId(),
                        time    = DateTime.Now,
                        type    = "Info",
                        content = "添加用户:" + model.name
                    });

                    return(new OperateResult
                    {
                        status = OperateStatus.Success,
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }
Esempio n. 3
0
        public OperateResult Login(User model)
        {
            using (SystemDB db = new SystemDB())
            {
                try
                {
                    var passwd = MD5Encode.Encode16(model.passwd);

                    var element = (from e in db.userList.Include("role")
                                   where e.passwd == passwd && e.name == model.name
                                   select e
                                   ).FirstOrDefault();
                    if (element != null)
                    {
                        if (element.status == "锁定")
                        {
                            return(new OperateResult
                            {
                                content = "用户被锁定",
                            });
                        }

                        //更新最后一次登录
                        element.lastLogin = DateTime.Now;

                        if (element.status == "未激活")
                        {
                            element.status = "激活";
                        }

                        db.Entry(element).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();

                        LogManager.Add(new LogRecord
                        {
                            userId  = element.id,
                            time    = DateTime.Now,
                            type    = "Info",
                            content = "登录系统"
                        });

                        return(new OperateResult
                        {
                            status = OperateStatus.Success,
                            content = "登录成功",
                            data = element
                        });
                    }


                    return(new OperateResult
                    {
                        content = "用户名或密码不正确"
                    });
                }
                catch (Exception ex)
                {
                    return(new OperateResult
                    {
                        content = ex.Message,
                    });
                }
            }
        }