Beispiel #1
0
 public UserViewModel(UserModel user)
 {
     if (user != null)
     {
         LoginName = user.LoginName;
         UserType = user.UserType;
         Name = user.Name;
         Phone = user.Phone;
         Description = user.Description;
         City = user.City;
     }
 }
Beispiel #2
0
        public void AddUser(UserModel user)
        {
            if (user == null || String.IsNullOrWhiteSpace(user.LoginName)
                || String.IsNullOrWhiteSpace(user.Password))
            {

            }
            UserRepository ur = new UserRepository();
            var u = ur.GetUser(user.LoginName);

            if (u != null)
            {
                throw new MobileException("该用户名已经存在,请重新输入用户名。", "", "user_has_exist");
            }

            user.Password = MD5Helper.GetMd5Hash(user.Password);
            var dbUser = ConvertBizUserToDbUser(user);
            dbUser = ur.AddUser(dbUser);
        }
Beispiel #3
0
        public UserModel ToUserModel()
        {
            UserModel u = new UserModel()
            {
                LoginName = this.LoginName,
                Name = this.Name,
                Password = this.Password,
                City = this.City,
                Phone = this.Phone,
                Description = this.Description,
                UserType = this.UserType
            };

            return u;
        }
Beispiel #4
0
        public bool Login(string userName, string password,out UserModel user, bool isAdminLoginFromPortal = false,string clientIP = null,string macAddr = null)
        {
            user = null;
            bool isLogin = false;
            string md5Password = isAdminLoginFromPortal ? MD5Helper.GetMd5Hash(password) : password;
            UserRepository ur = new UserRepository();
            User dbuser = ur.Login(userName, md5Password);

            if (dbuser != null)
            {
                user = ConvertDBUserToBizUser(dbuser);
                // 客户端用户不能登录后台管理系统
                if (isAdminLoginFromPortal && (int)RoleType.ClientUsers == user.UserType)
                {
                    isLogin = false;
                }
                else
                {
                    isLogin = true;

                    TokenRepository tr = new TokenRepository();
                    var tokenModel = new token
                    {
                        IP = clientIP,
                        MacAddr = macAddr,
                        UserName = userName
                    };

                    user.Token = tr.NewToken(tokenModel);
                    // login success, add login record
                    LoginRecordRepository recordRep = new LoginRecordRepository();
                    LoginRecord loginRecord = new LoginRecord
                    {
                        IsLoginFromClient = isAdminLoginFromPortal ? 0 : 1,
                        LoginIP = clientIP,
                        UserName = userName
                    };

                    recordRep.Add(loginRecord);
                }
            }

            return isLogin;
        }
Beispiel #5
0
        private UserModel ConvertDBUserToBizUser(User dbUser)
        {
            UserModel user = new UserModel()
            {
                LoginName = dbUser.UserName,
                Name = dbUser.FullName,
                UserType = dbUser.UserType,
                Address = dbUser.Address,
                City = dbUser.City,
                Province = dbUser.Province,
                Password = dbUser.Password,
                Phone = dbUser.Phone,
                Email = dbUser.Email,
                Description = dbUser.Description,
                CreatedBy = dbUser.CreatedBy,
                CreatedDate = dbUser.CreatedDate.HasValue? dbUser.CreatedDate.Value : DateTime.MinValue,
                LastUpdatedBy = dbUser.LastUpdatedBy,
                LastUpdatedDate = dbUser.LastUpdatedDate.HasValue ? dbUser.LastUpdatedDate.Value : DateTime.MinValue
            };

            return user;
        }
Beispiel #6
0
        private User ConvertBizUserToDbUser(UserModel user)
        {
            User dbUser = new User()
            {
                UserName = user.LoginName,
                FullName = user.Name,
                UserType = user.UserType,
                Address = user.Address,
                City = user.City,
                Province = user.Province,
                Password = user.Password,
                Phone = user.Phone,
                Email = user.Email,
                Description = user.Description,
                CreatedBy = user.CreatedBy,
                LastUpdatedBy = user.LastUpdatedBy
            };

            return dbUser;
        }