Example #1
0
        public JsonResult Login(SecUser model, string ValidateCode)
        {
            MyJsonResult mjr = new MyJsonResult();

            try
            {
                var obj = Session["ValidateCode"];
                if (obj == null || obj.ToString() != ValidateCode)
                {
                    mjr.Success = false;
                    mjr.Message = "验证码不正确!";
                    mjr.Data = 1;
                    if (obj == null)
                    {
                        mjr.Data = 11;
                    }
                    return Json(mjr);
                }

                UserService userService = new UserService();

                var user = userService.GetUserByLoginName(model.LoginName);

                if (user == null)
                {
                    mjr.Success = false;
                    mjr.Message = "用户名不正确!";
                    mjr.Data = 2;
                }
                else
                {
                    if (user.Password != model.Password)
                    {
                        mjr.Success = false;
                        mjr.Message = "密码不正确!";
                        mjr.Data = 3;
                    }
                    else
                    {
                        SecurityContext.Current = new SecurityContext()
                        {
                            User = user,
                            PermissionManager = new PermissionManager(user.UserId)
                        };

                        //Session[SSessionIndex.IsAuthorizedForCKEditor] = true;
                        mjr.Success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                mjr.Success = false;
                mjr.Message = ex.Message;
            }

            return Json(mjr);
        }
Example #2
0
        public JsonResult Save(SecUser model)
        {
            MyJsonResult mjr = new MyJsonResult();

            using (var dba = DbAccessor.Create())
            {
                try
                {
                    dba.BeginTran();

                    model.ModifiedById = SecurityContext.Current.User.UserId;
                    model.ModifiedDate = DateTime.Now;

                    if (model.UserId == null)
                    {

                        #region 校验数据
                        dynamic count = _dba.ExecuteScalar<dynamic>("SecuritySettings.User.CountByLoginName",
                                           new { LoginName = model.LoginName, Status = (int)StatusType.Enabled });

                        if (count > 0)
                        {
                            mjr.Success = false;
                            mjr.Message = "登录名已存在!";
                            goto End;
                        } 
                        #endregion

                        model.UserId = Guid.NewGuid().ToString();
                        model.Status = (int)StatusType.Enabled;
                        model.CreatedById = SecurityContext.Current.User.UserId;
                        model.CreatedDate = DateTime.Now;
                        dba.Insert<SecUser>(model);
                    }
                    else
                    {
                        dba.UpdateFields(model, "LoginName", "Password", "Name", "Sex", "Birthday",
                            "MobilePhone", "OrganizationId",
                            "ModifiedById", "ModifiedDate");
                    }

                    dba.CommitTran();
                    mjr.Success = true;
                    mjr.Message = "保存成功!";
                }
                catch (Exception ex)
                {
                    dba.RollbackTran();
                    mjr.Success = false;
                    mjr.Message = ex.Message;
                }
            }

            End:

            return Json(mjr);
        }
Example #3
0
        public ActionResult Edit(string id)
        {
            SecUser user = new SecUser();
            if (id != null)
            {
                user = _userService.Get(id);
                string strSql = @"SELECT Name FROM Sec_Organization WHERE OrganizationId=#OrganizationId#";
                string orgName = _dba.ExecuteScalar<string>(strSql, new { OrganizationId = user.OrganizationId });

                ViewBag.OrgName = orgName;
                
            }
            return View(user);
        }
Example #4
0
        public JsonResult Delete(string id)
        {
            MyJsonResult mjr = new MyJsonResult();


            try
            {
                var user = new SecUser();
                user.UserId = id;
                user.Status =(int)StatusType.Deleted;
                _dba.UpdateFields(user, "Status");

                mjr.Success = true;
            }
            catch (Exception ex)
            {

                mjr.Success = false;
                mjr.Message = ex.Message;
            }
      
            return Json(mjr);
        }