Beispiel #1
0
        public bool AddUser(UserModel useradd)
        {
            using (CarRentalEntities db = new CarRentalEntities())
            {
                User newuser = db.Users.Where(a => a.UserID == useradd.UserID).FirstOrDefault();
                if (newuser != null)
                {
                    return(false);
                }
            };

            User u = new User
            {
                //UserID = useradd.UserID,
                FullName   = useradd.FullName,
                TeudatZeut = useradd.TeudatZeut,
                UserName   = useradd.UserName,
                Email      = useradd.Email,
                Gender     = useradd.Gender,
                Password   = useradd.Password,

                IsValidUSer = useradd.IsValidUSer,
                //PicPath = useradd.PicPath,
                Birthday = useradd.Birthday,
                //UserTypeID = useradd.UserTypeID
            };

            try

            {
                db.Users.Add(u);
                db.SaveChanges();
                var             typeofuser  = db.Users.Where(x => x.UserTypeID == u.UserTypeID).FirstOrDefault();
                var             userStore   = new UserStore <ApplicationUser>(new ApplicationDbContext());
                var             userManager = new UserManager <ApplicationUser>(userStore);
                ApplicationUser uIdentity   = new ApplicationUser
                {
                    UserID      = useradd.UserID,
                    BirthDate   = useradd.Birthday,
                    UserTypeID  = useradd.UserTypeID,
                    FullName    = useradd.FullName,
                    TeudatZeut  = useradd.TeudatZeut,
                    UserName    = useradd.UserName,
                    Email       = useradd.Email,
                    Gender      = useradd.Gender,
                    Password    = useradd.Password,
                    IsValidUSer = useradd.IsValidUSer,
                    PicPath     = useradd.PicPath,
                    Phone       = useradd.Phone

                                  // TypeOfUser = typeofuser.UserType.TypeOfUser
                };
                //IdentityResult identified = userManager.Create(uIdentity, useradd.Password);

                return(true);
            }
            catch (System.Data.Entity.Core.UpdateException)
            {
                return(false);
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException) //DbContext
            {
                return(false);
            }
        }
Beispiel #2
0
        public BaseModel ResetMobile(string token, string password, string mobileNum, string smsCode)
        {
            try
            {
                #region 非数据库端验证token
                BaseModel cv_Token = ClientValidateToken(token);
                if (cv_Token.Code != 0)
                {
                    return(cv_Token);
                }
                #endregion

                #region 非数据库端验证mobileNum
                BaseModel cv_MobileNum = ClientValidateMobileNum(mobileNum);
                if (cv_MobileNum.Code != 0)
                {
                    return(cv_MobileNum);
                }
                #endregion

                #region 非数据库端验证smsCode
                BaseModel cv_SMSCode = ClientValidateSMSCode(smsCode);
                if (cv_SMSCode.Code != 0)
                {
                    return(cv_SMSCode);
                }
                #endregion

                #region 非数据库端验证password
                BaseModel cv_Password = ClientValidatePassword(password);
                if (cv_Password.Code != 0)
                {
                    return(cv_Password);
                }
                #endregion

                UserModel TokenModel = userDAL.GetByToken(token);
                #region 数据库端验证token
                BaseModel sv_Token = ServerValidateToken(TokenModel);
                if (sv_Token.Code != 0)
                {
                    return(sv_Token);
                }
                #endregion

                DateTime dt  = DateTime.Now;
                DateTime dt2 = dt.AddMinutes(0 - ConfigHelper.SMSTime);

                #region 数据库端验证smsCode
                BaseModel sv_SMSCode = ServerValidateSMSCode(smsCode, mobileNum, dt2);
                if (sv_SMSCode.Code != 0)
                {
                    return(sv_SMSCode);
                }
                #endregion

                UserModel userModel = userDAL.GetByMobile(mobileNum);
                #region 数据库端验证mobileNum
                BaseModel sv_MobileNum = ServerValidateMobileNum(userModel);
                if (sv_MobileNum.Code != 0)
                {
                    return(sv_MobileNum);
                }
                #endregion

                #region 更新用户手机号

                if (TokenModel.Password != EncryptHelper.MD5Encrypt(password + ConfigHelper.Salt))
                {
                    return(new BaseModel()
                    {
                        Code = (int)CodeEnum.密码错误, Msg = string.Format(CodeMsgDAL.GetByCode((int)CodeEnum.密码错误))
                    });
                }
                TokenModel.MobileNum = mobileNum;

                if (userDAL.Update(TokenModel))
                {
                    return(new BaseModel()
                    {
                        Code = (int)CodeEnum.成功, Msg = string.Format(CodeMsgDAL.GetByCode((int)CodeEnum.成功))
                    });
                }
                else
                {
                    return(new BaseModel()
                    {
                        Code = (int)CodeEnum.失败, Msg = string.Format(CodeMsgDAL.GetByCode((int)CodeEnum.失败))
                    });
                }
                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(new BaseModel()
                {
                    Code = (int)CodeEnum.系统异常, Msg = CodeMsgDAL.GetByCode((int)CodeEnum.系统异常)
                });
            }
        }
        public async Task <bool> Create(UserModel user)
        {
            var mapper = Mapper.Map <User>(user);

            return(Mapper.Map <bool>(await _repository.Create(mapper, user.Password)));
        }