public ActionResult UserRequests(int id, string type)
        {
            if (id != 0 && !string.IsNullOrEmpty(type) && type != "0")
            {
                try
                {
                    var userRequest = UserRequestsRepo.LoadRequests().Data.FirstOrDefault(d => d.ID == id);
                    var userInfo    = new UserInfo()
                    {
                        Address    = userRequest.Address,
                        Email      = userRequest.Email,
                        Name       = userRequest.Name,
                        Password   = userRequest.Password,
                        UserName   = userRequest.UserName,
                        UserTypeID = Int32.Parse(type)
                    };
                    UserInfoRepo.Save(userInfo);
                    UserRequestsRepo.deleteRequest(id);
                    new Thread(() =>
                    {
                        Thread.CurrentThread.IsBackground = true;
                        /* run your code here */
                        ForgotPassword.ConfirmationMail(userRequest.Email, userRequest.Name, "Your account has been created Successfully. Please go to the following link to continue.", userRequest.UserName, userRequest.Password);
                    }).Start();

                    //TempData["ConfirmationMsg"] = "A confirmation mail has been sent";
                }
                catch (Exception ex)
                {
                }
            }
            return(JavaScript("location.reload(true)"));
        }
Beispiel #2
0
        /// <summary>
        /// 删除UserInfo信息
        /// </summary>
        /// <param name="ids">要删除的Id编号</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> DeleteUserInfos(params int[] ids)
        {
            ids.CheckNotNull("ids");
            await UserInfoRepo.RecycleAsync(p => ids.Contains(p.Id));

            return(new OperationResult(OperationResultType.Success, "删除成功"));
        }
 /// <summary>
 /// 检查UserInfo信息是否存在
 /// </summary>
 /// <param name="predicate">检查谓语表达式</param>
 /// <param name="id">更新的UserInfo编号</param>
 /// <returns>UserInfo信息是否存在</returns>
 public async Task <bool> CheckUserInfoExists(Expression <Func <UserInfo, bool> > predicate, int id = 0)
 {
     return(await Task.Run(() =>
     {
         return UserInfoRepo.CheckExists(predicate, id);
     }));
 }
Beispiel #4
0
        public ActionResult LogIn(LogInModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = UserInfoRepo.Login(model.UserName, model.Password);

            if (result.HasError)
            {
                ViewBag.Error = result.Message;
                return(View(model));
            }
            var userProfile = new UserProfile()
            {
                ID         = result.Data.ID,
                Name       = result.Data.Name,
                UserName   = result.Data.UserName,
                Email      = result.Data.Email,
                UserTypeID = result.Data.UserTypeID
            };
            var UserProfileJason = JsonConvert.SerializeObject(userProfile);

            FormsAuthentication.SetAuthCookie(UserProfileJason, false);
            return(RedirectToAction("Home", "Main"));
        }
Beispiel #5
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     base.OnActionExecuting(filterContext);
     SysUser user = null;
     if (Request.IsAuthenticated)
     {
         try
         {
             user = User.Identity.GetUserName().FromJsonString<SysUser>();
             var singleOrDefault = UserInfoRepo.GetByPredicate(x => x.SysUser.Id == user.Id).SingleOrDefault();
             if (singleOrDefault != null)
             {
                 Uid = singleOrDefault.Id;
                 HeadPic = singleOrDefault.HeadPic;
                 LoginName = singleOrDefault.SysUser.NickName;
                 UserTypes = singleOrDefault.SysUser.UserType;
                 ViewBag.UserId = Uid;
                 ViewBag.NickName = LoginName;
             }
         }
         catch
         {
         }
     }
     ViewBag.HeadPic = HeadPic;
     ViewBag.Uid = Uid;
 }
Beispiel #6
0
        private async Task <OperationResult> Login(string userName, string registKey, LoginDevice loginDevice, string clientVersion)
        {
            //更新最后一次登录的RegistKey
            var theUser = await UserInfos.SingleOrDefaultAsync(p => p.SysUser.UserName == userName);

            if (theUser == null)
            {
                return(new OperationResult(OperationResultType.ValidError, "数据错误", null));
            }

            if (theUser.RegistKey != registKey)
            {
                theUser.RegistKey = registKey;
                await UserInfoRepo.UpdateAsync(theUser);
            }

            //变更登录信息
            await ResetToken(theUser, loginDevice, clientVersion);

            var loginInfo = new UserTokenDto()
            {
                Id       = theUser.Id,
                NickName = theUser.SysUser.NickName,
                HeadPic  = theUser.HeadPic,
                Sex      = theUser.Sex,
                Token    = theUser.Token
            };

            return(new OperationResult(OperationResultType.Success, "登录成功", loginInfo));
        }
Beispiel #7
0
        public ActionResult UserProfile(Result <UserInfo> userInfo, string pass, string cPass)
        {
            userInfo.Data.Pass = pass;

            /*if (!ModelState.IsValid)
             * {
             *  return View(userInfo);
             * }*/

            if (!pass.Equals(cPass))
            {
                return(Content("Password and Confirm Password Should be Matched"));
            }
            //userInfo.Data.Pass = pass;
            var result = UserInfoRepo.Save(userInfo.Data);

            if (result.HasError)
            {
                userInfo.HasError = true;
                userInfo.Message  = result.Message;
                return(View(userInfo));
            }

            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="registKey">极光registKey</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <param name="type">登录方式</param>
        /// <returns></returns>
        public async Task <OperationResult> Login(string userName, string password, string registKey, LoginDevice loginDevice, string clientVersion, int type)
        {
            userName.CheckNotNullOrEmpty("userName");
            password.CheckNotNullOrEmpty("password");

            SysUser sUser = await UserManager.FindByNameAsync(userName);

            if (sUser == null)
            {
                return(new OperationResult(OperationResultType.ValidError, "用户不存在", 0));
            }
            if (sUser.IsLocked)
            {
                return(new OperationResult(OperationResultType.ValidError, "您的账号已被冻结,请联系客服", 0));
            }
            if (type == 2)
            {
                //验证码
                var severCode = GetValidateCode(userName, CodeType.临时密码);
                if (severCode == null || severCode.Code != password)
                {
                    return(new OperationResult(OperationResultType.ValidError, "临时密码错误", 0));
                }
            }
            else
            {
                if (!await UserManager.CheckPasswordAsync(sUser, password))
                {
                    return(new OperationResult(OperationResultType.ValidError, "用户名或密码错误", null));
                }
            }
            if (sUser.UserType != UserType.App用户)
            {
                return(new OperationResult(OperationResultType.QueryNull, "用户不存在", null));
            }
            //更新最后一次登录的RegistKey
            var theUser = await UserInfos.SingleOrDefaultAsync(p => p.SysUser.UserName == userName);

            if (theUser.RegistKey != registKey)
            {
                theUser.RegistKey = registKey;
                await UserInfoRepo.UpdateAsync(theUser);
            }

            //变更登录信息
            await ResetToken(theUser, loginDevice, clientVersion);

            var loginInfo = new UserTokenDto()
            {
                Id       = theUser.Id,
                NickName = theUser.SysUser.NickName,
                HeadPic  = theUser.HeadPic,
                Sex      = theUser.Sex,
                PhoneNo  = theUser.SysUser.PhoneNumber,
                Token    = theUser.Token
            };

            //return new OperationResult(OperationResultType.Success, "登录成功", sUser);
            return(new OperationResult(OperationResultType.Success, "登录成功", loginInfo));
        }
Beispiel #9
0
        /// <summary>
        /// 验证用户注册
        /// </summary>
        /// <param name="dto">用户注册信息</param>
        /// <param name="validateCode">验证码</param>
        /// <returns>业务操作结果</returns>

        public async Task <OperationResult> ValidateRegister(UserInfoRegistDto dto, string validateCode)
        {
            dto.CheckNotNull("dto");
            validateCode.CheckNotNullOrEmpty("validateCode");
            //验证码
            var severCode = GetValidateCode(dto.UserName, CodeType.用户注册);

            if (severCode == null || severCode.Code != validateCode)
            {
                return(new OperationResult(OperationResultType.ValidError, "验证码错误", 0));
            }
            if (SysUserRepo.CheckExists(p => p.UserName == dto.UserName))
            {
                return(new OperationResult(OperationResultType.ValidError, "账号已被使用", 0));
            }

            try
            {
                UserInfoRepo.UnitOfWork.TransactionEnabled = true;
                //验证密码格式
                IdentityResult result = await UserManager.PasswordValidator.ValidateAsync(dto.Password);

                if (!result.Succeeded)
                {
                    return(result.ToOperationResult());
                }

                SysUser sUser = new SysUser()
                {
                    UserName     = dto.UserName,
                    NickName     = dto.NickName,
                    PasswordHash = UserManager.PasswordHasher.HashPassword(dto.Password),//密码加密
                    UserType     = UserType.App用户
                };
                if (severCode.ValidateType == ValidateType.手机)
                {
                    sUser.PhoneNumber          = dto.UserName;
                    sUser.PhoneNumberConfirmed = true;
                }
                else
                {
                    sUser.Email          = dto.UserName;
                    sUser.EmailConfirmed = true;
                }
                await UserManager.CreateAsync(sUser);

                var userInfo = Mapper.Map <UserInfo>(dto);
                userInfo.SysUser = sUser;
                await UserInfoRepo.InsertAsync(userInfo);

                await UserInfoRepo.UnitOfWork.SaveChangesAsync();

                return(new OperationResult(OperationResultType.Success, "注册成功", userInfo.Id));
            }
            catch
            {
                return(new OperationResult(OperationResultType.NoChanged, "注册失败", 0));
            }
        }
        public ActionResult Registration(RegistrationModel registrationModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(registrationModel));
            }

            MD5 md5 = MD5.Create();

            byte[]        bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(registrationModel.CPass);
            byte[]        hash  = md5.ComputeHash(bytes);
            StringBuilder sb    = new StringBuilder();

            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            var Hashedpass = sb.ToString();

            var companyInfo = new CompanyInfo()
            {
                CName          = registrationModel.CName,
                TradeLicenseNo = registrationModel.TradeLicenseNo,
                Website        = registrationModel.Website,
                CEmail         = registrationModel.CEmail,
                PhnNumber      = registrationModel.PhnNumber,
                Address        = registrationModel.Address,
                City           = registrationModel.City,
                Zip            = registrationModel.Zip
            };

            var userInfo = new UserInfo()
            {
                FirstName     = registrationModel.FirstName,
                LastName      = registrationModel.LastName,
                UEmail        = registrationModel.UEmail,
                Pass          = Hashedpass,
                TimeZone      = registrationModel.TimeZone,
                PreferredRoe  = registrationModel.PreferredRoe,
                UserTypeID    = (int)EnumCollection.UserTypeEnum.Agent,
                AdminVerifyID = (int)EnumCollection.AdminVarifyEnum.NotAccept,
                CompanyInfo   = companyInfo,
            };

            var result = UserInfoRepo.Save(userInfo);

            if (result.HasError)
            {
                ViewBag.Error = result.Message;
                return(View(registrationModel));
            }

            SendMail(registrationModel.CEmail);

            Session["uEmail"] = registrationModel.UEmail;


            return(RedirectToAction("Login"));
        }
Beispiel #11
0
        /// <summary>
        /// 编辑UserInfo信息
        /// </summary>
        /// <param name="dtos">要更新的UserInfoEditDto信息</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> EditUserInfos(params UserInfoEditDto[] dtos)
        {
            dtos.CheckNotNull("dtos");

            OperationResult result = await Task.Run(() => UserInfoRepo.Update(dtos));

            return(result);
        }
Beispiel #12
0
        // GET: Admin
        public ActionResult List(string key = "")
        {
            /*if (MessageBox.Show("Are You Sure ?", "Confirmation", MessageBoxButtons.YesNo) == DialogResult.No)
             *  return RedirectToAction("Index", "Admin");*/
            var result = UserInfoRepo.PendingAgent(key);

            return(View(result));
        }
        /// <summary>
        /// 三方登录
        /// </summary>
        /// <param name="thirdKey">三方key</param>
        /// <param name="thirdProvider">微博?QQ?微信?</param>
        /// <param name="loginDevice">登录设备 IOS?Android?</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <param name="registKey">极光推送Key</param>
        /// <returns></returns>
        public async Task <OperationResult> LoginByThird(string thirdKey, ThirdProvider thirdProvider, LoginDevice loginDevice, string clientVersion, string registKey = "")
        {
            var thirdUser = SysUserLoginRepo.Entities.SingleOrDefault(m => m.ProviderKey == thirdKey && m.ThridProvider == thirdProvider);

            if (thirdUser == null)
            {
                var     userName = "******" + DateTime.Now.ToString("yyyyMMddhhffff");
                SysUser sUser    = new SysUser()
                {
                    UserName = userName,
                    NickName = userName,
                    UserType = UserType.App用户,
                };
                UserInfoRepo.UnitOfWork.TransactionEnabled = true;
                await UserManager.CreateAsync(sUser);

                var userInfo = new UserInfo()
                {
                    SysUser   = sUser,
                    IsDeleted = false,
                    Sex       = Sex.限,
                };
                await UserInfoRepo.InsertAsync(userInfo);

                thirdUser = new SysUserLogin()
                {
                    ProviderKey   = thirdKey,
                    ThridProvider = thirdProvider,
                    User          = sUser,
                };
                await SysUserLoginRepo.InsertAsync(thirdUser);

                await UserInfoRepo.UnitOfWork.SaveChangesAsync();
            }

            var theUser = UserInfoRepo.Entities.SingleOrDefault(m => m.SysUser.Id == thirdUser.User.Id);

            if (theUser.RegistKey != registKey)
            {
                theUser.RegistKey = registKey;
                await UserInfoRepo.UpdateAsync(theUser);
            }

            //变更登录信息
            await ResetToken(theUser, loginDevice, clientVersion);

            var loginInfo = new UserTokenDto()
            {
                Id       = theUser.Id,
                NickName = theUser.SysUser.NickName,
                HeadPic  = theUser.HeadPic,
                Sex      = theUser.Sex,
                Token    = theUser.Token
            };

            return(CdkxResult.Success(loginInfo));
        }
Beispiel #14
0
        /// <summary>
        /// 编辑UserInfo信息
        /// </summary>
        /// <param name="dtos">要更新的UserInfoEditDto信息</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> EditUserInfos(params UserInfoEditDto[] dtos)
        {
            dtos.CheckNotNull("dtos");

            var result = UserInfoRepo.Update(dtos, updateFunc: (dto, userInfo) =>
            {
                var sysUser      = userInfo.SysUser;
                sysUser.NickName = dto.NickName;
                return(userInfo);
            });

            return(await Task.FromResult(result));
        }
Beispiel #15
0
 public BoPriver(
     IHostingEnvironment environment,
     IMapper mapper,
     Ken_testContext context,
     UserInfoRepo userInfoRepo,
     MessageLogRepo messageLogRepo)
 {
     _environment    = environment;
     _mapper         = mapper;
     _context        = context;
     _userInfoRepo   = userInfoRepo;
     _messageLogRepo = messageLogRepo;
 }
Beispiel #16
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="registKey">极光registKey</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <returns></returns>
        public async Task <OperationResult> Login(string userName, string password, string registKey, LoginDevice loginDevice, string clientVersion)
        {
            userName.CheckNotNullOrEmpty("userName");
            password.CheckNotNullOrEmpty("password");

            SysUser sUser = await UserManager.FindByNameAsync(userName);

            var result = await UserManager.CheckPasswordAsync(sUser, password);

            if (sUser == null || sUser.UserType != UserType.App用户)
            {
                return(new OperationResult(OperationResultType.QueryNull, "用户不存在", null));
            }
            else if (sUser.IsLocked)
            {
                return(new OperationResult(OperationResultType.ValidError, "该账号已被冻结,请联系客服。", null));
            }
            else if (!await UserManager.CheckPasswordAsync(sUser, password))
            {
                return(new OperationResult(OperationResultType.ValidError, "用户名或密码错误", null));
            }
            else
            {
                //更新最后一次登录的RegistKey
                var theUser = await UserInfos.SingleOrDefaultAsync(p => p.SysUser.UserName == userName);

                if (theUser == null)
                {
                    return(new OperationResult(OperationResultType.ValidError, "数据错误", null));
                }

                if (theUser.RegistKey != registKey)
                {
                    theUser.RegistKey = registKey;
                    await UserInfoRepo.UpdateAsync(theUser);
                }

                //变更登录信息
                await ResetToken(theUser, loginDevice, clientVersion);

                var loginInfo = new UserTokenDto()
                {
                    Id       = theUser.Id,
                    NickName = theUser.SysUser.NickName,
                    HeadPic  = theUser.HeadPic,
                    Sex      = theUser.Sex,
                    Token    = theUser.Token
                };
                return(new OperationResult(OperationResultType.Success, "登录成功", loginInfo));
            }
        }
        public ActionResult ForgotPassword(UserInfo userInfo)
        {
            var         result      = UserInfoRepo.ForgotPassword(userInfo.CompanyInfo.CEmail);
            MailMessage mailMessage = new MailMessage("*****@*****.**", userInfo.CompanyInfo.CEmail);

            mailMessage.Subject = "Password Recovery";
            mailMessage.Body    = "Your Password is: " + result.Data.Pass;

            SmtpClient smtpClient = new SmtpClient();

            smtpClient.Send(mailMessage);

            return(View("Login"));
        }
Beispiel #18
0
        public ActionResult UserProfile()
        {
            var result = UserInfoRepo.GetById(HttpUtil.Current.ID);

            if (result.HasError)
            {
                ViewBag.Error = result.Message;
                return(RedirectToAction("Index", "Admin"));
            }

            var userProfile = new UserInfo();

            return(View(result));
        }
Beispiel #19
0
        public Header()
        {
            InitializeComponent();

            if (this.NotInDesignMode())
            {
                _apiSettings = DIService.GetSingleton<ApiSettings>();
                _sessionInfoRepo = DIService.GetSingleton<SessionInfoRepo>();
                _userInfoRepo = DIService.GetSingleton<UserInfoRepo>();
                _avatarRepo = DIService.GetSingleton<AvatarRepo>();
                _dialogMessagesRepo = DIService.GetSingleton<DialogMessagesRepo>();

                UpdateHeaderInfo();
            }
        }
        public MessageItem(IDialogMessage message)
        {
            InitializeComponent();

            if (this.NotInDesignMode())
            {
                _userInfoRepo = DIService.GetSingleton<UserInfoRepo>();
                _friendsRepo = DIService.GetSingleton<FriendsRepo>();

                FirstNameLabel.Content = GetFirstName(message.Out ? message.VkUserId : message.VkFriendId);
                DateLabel.Content = DateTime.Today == message.Date.Date ? message.Date.ToTimeString() : message.Date.ToDateString();
                BodyLabel.Text = message.Body;
                ReadState = message.ReadState;
            }
        }
Beispiel #21
0
        /*[HttpPost]
         * public ActionResult UserProfile(string name)
         * {
         *  return Content(name);
         * }*/

        public ActionResult AcceptPendingAgent(int pendingAgentId)
        {
            if (MessageBox.Show("Are You Sure ?", "Confirmation", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return(RedirectToAction("List", "AgentInfo"));
            }

            var result = UserInfoRepo.AcceptByAdmin(pendingAgentId);

            if (result.HasError)
            {
                ViewBag.Error = result.Message;
                return(RedirectToAction("List", "AgentInfo"));
            }
            return(RedirectToAction("List", "AgentInfo"));
        }
Beispiel #22
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            string id     = model.id;
            var    result = UserInfoRepo.ChangePassword(Request["id"].ToString(), model.NewPassword);

            if (result.HasError)
            {
                ViewBag.Error = result.Message;
                return(View(model));
            }
            ViewBag.Success = "Your password has been changed successfully";
            return(View(model));
        }
Beispiel #23
0
        /// <summary>
        /// 修改用户昵称和头像
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="nickName"></param>
        /// <param name="headPic"></param>
        /// <returns></returns>
        public async Task <OperationResult> EditUserInfo(int userId, string nickName, string headPic)
        {
            UserInfoRepo.UnitOfWork.TransactionEnabled = true;
            var info = UserInfoRepo.GetByKey(userId);

            info.HeadPic = headPic;
            await UserInfoRepo.UpdateAsync(info);

            var sys = info.SysUser;

            sys.NickName = nickName;
            var result = await SysUserRepo.UpdateAsync(sys);

            await UserInfoRepo.UnitOfWork.SaveChangesAsync();

            return(new OperationResult(OperationResultType.Success, "修改成功"));
        }
Beispiel #24
0
        /// <summary>
        /// 保存UserInfo信息(新增/更新)
        /// </summary>
        /// <param name="updateForeignKey">更新时是否更新外键信息</param>
        /// <param name="dtos">要保存的UserInfoDto信息</param>
        /// <returns>业务操作集合</returns>
        public async Task <OperationResult> SaveUserInfos(bool updateForeignKey = false, params UserInfoDto[] dtos)
        {
            try
            {
                dtos.CheckNotNull("dtos");
                var addDtos    = dtos.Where(p => p.Id == 0).ToArray();
                var updateDtos = dtos.Where(p => p.Id != 0).ToArray();

                UserInfoRepo.UnitOfWork.TransactionEnabled = true;

                Action <UserInfoDto> checkAction = dto =>
                {
                    if (UserInfoRepo.CheckExists(p => p.PhoneNo == dto.PhoneNo, dto.Id))
                    {
                        throw new Exception("“{0}”已被使用".FormatWith("手机号"));
                    }
                };
                Func <UserInfoDto, UserInfo, UserInfo> updateFunc = (dto, entity) =>
                {
                    if (dto.Id == 0 || updateForeignKey)
                    {
                        entity.SysUser = SysUserRepo.GetByKey(dto.SysUserId);
                    }
                    return(entity);
                };
                if (addDtos.Length > 0)
                {
                    UserInfoRepo.Insert(addDtos, checkAction, updateFunc);
                }
                if (updateDtos.Length > 0)
                {
                    UserInfoRepo.Update(updateDtos, checkAction, updateFunc);
                }
                await UserInfoRepo.UnitOfWork.SaveChangesAsync();

                return(new OperationResult(OperationResultType.Success, "保存成功"));
            }
            catch (Exception e)
            {
                return(new OperationResult(OperationResultType.Error, e.Message));
            }
        }
        /// <summary>
        /// 重置用户Token有效期
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <returns></returns>
        public async Task <OperationResult> ResetToken(UserInfo user, LoginDevice loginDevice, string clientVersion)
        {
            Operator oper = new Operator()
            {
                UserId         = user.Id.ToString(),
                UserName       = user.SysUser.UserName,
                LoginDevice    = loginDevice,
                PhoneNo        = user.SysUser.PhoneNumber,
                ClientVersion  = clientVersion,
                ValidatePeriod = DateTime.Now.AddDays(30),//默认30天有效期
                UserDatas      = new Dictionary <string, object>()
            };
            string strAuth = oper.ToJsonString();

            user.Token = DesHelper.Encrypt(strAuth, OSharp.Core.Constants.BodeAuthDesKey);

            await UserInfoRepo.UpdateAsync(user);

            return(new OperationResult(OperationResultType.Success, "重置成功", user.Token));
        }
Beispiel #26
0
        /// <summary>
        /// 重置用户Token有效期
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <returns></returns>
        public async Task <OperationResult> ResetToken(UserInfo user, LoginDevice loginDevice, string clientVersion)
        {
            Operator oper = new Operator()
            {
                UserId         = user.Id.ToString(),
                UserName       = user.SysUser.UserName,
                LoginDevice    = loginDevice,
                PhoneNo        = user.SysUser.PhoneNumber,
                ClientVersion  = clientVersion,
                ValidatePeriod = DateTime.Now.AddDays(30)//默认30天有效期
            };
            string authDesKey = "bodeauth";
            string strAuth    = oper.ToJsonString();

            user.Token = DesHelper.Encrypt(strAuth, authDesKey);

            await UserInfoRepo.UpdateAsync(user);

            return(new OperationResult(OperationResultType.Success, "重置成功"));
        }
        /// <summary>
        /// 邮箱绑定
        /// </summary>
        /// <param name="validateCode"></param>
        /// <param name="nweEmail"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public OperationResult ChangeEmail(string validateCode, string nweEmail, string userName)
        {
            var severCode = GetValidateCode(userName, CodeType.找回密码);

            if (severCode == null || severCode.Code != validateCode)
            {
                return(new OperationResult(OperationResultType.ValidError, "验证码错误", 0));
            }
            var userInfo  = UserInfoRepo.GetByPredicate(x => x.SysUser.UserName == userName);
            var userInfos = userInfo as UserInfo[] ?? userInfo.ToArray();

            if (!userInfos.Any())
            {
                return(new OperationResult(OperationResultType.ValidError, "身份信息错误", 0));
            }
            //smtp.163.com
            string senderServerIp = "123.125.50.133";
            //string senderServerIp = "smtp.163.com";
            //smtp.gmail.com
            //string senderServerIp = "74.125.127.109";
            //string senderServerIp = "smtp.qq.com";
            //string senderServerIp = "58.251.149.147";
            //string senderServerIp = "smtp.sina.com";
            string url = ConfigurationManager.AppSettings["ServerHost"] + "Web/Home/EmailBack?e=" + DataCode.Base64Encrypt(nweEmail, Encoding.UTF8) + "&u=" + userInfos.Single().Id + "&p=" + userInfos.Single().SysUser.PasswordHash + "";

            url = url.Replace("+", "%2B");
            string fromMailAddress = ConfigurationManager.AppSettings["Email"];//"*****@*****.**";
            string subjectInfo     = "邮箱绑定【西部鞋都】";
            string bodyInfo        = "你正在进行邮箱绑定操作,如果是你本人操作,请点击下面的链接完成邮箱绑定。【西部鞋都】<br/> <a href=\"" + url + "\">" + url + "</a>";
            string mailUsername    = "******";
            string mailPassword    = ConfigurationManager.AppSettings["EmailPwd"]; //发送邮箱的密码
            string mailPort        = "25";

            MailSender emailSender = new MailSender(senderServerIp, nweEmail, fromMailAddress, subjectInfo, bodyInfo, mailUsername, mailPassword, mailPort, false, false);

            emailSender.Send();
            return(new OperationResult(OperationResultType.Success, "请到邮箱完成验证", 0));
        }
Beispiel #28
0
        /// <summary>
        /// 获取手机验证码
        /// </summary>
        /// <param name="phoneNo">手机号</param>
        /// <param name="codeType"></param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> GetSmsValidateCode(string phoneNo, CodeType codeType)
        {
            if (codeType == CodeType.用户注册)
            {
                if (UserInfoRepo.CheckExists(p => p.SysUser.UserName == phoneNo))
                {
                    return(new OperationResult(OperationResultType.ValidError, "手机号已注册,不能获取注册验证码"));
                }
            }
            if (codeType == CodeType.找回密码)
            {
                if (!UserInfoRepo.CheckExists(p => p.SysUser.UserName == phoneNo))
                {
                    return(new OperationResult(OperationResultType.ValidError, "该用户未注册,不能获取验证码"));
                }
            }

            return(await SendValidateCode(phoneNo, ValidateType.手机, codeType, code =>
            {
                var smsContent = "您的验证码为:" + code + ",请勿泄露。[不同]";
                Sms.Send(phoneNo, 1, smsContent);
            }));
        }
Beispiel #29
0
        public ActionResult Registration(RegistrationModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var UserInfo = new UserInfo()
            {
                UserName   = model.UserName,
                Name       = model.Name,
                Email      = model.Email,
                Password   = model.Password,
                UserTypeID = (int)model.userTypeID
            };
            var result = UserInfoRepo.Save(UserInfo);

            if (result.HasError)
            {
                ViewBag.Error = result.Message;
                return(View(model));
            }
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #30
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="phoneNo">手机号</param>
        /// <param name="password">密码</param>
        /// <param name="registKey">极光registKey</param>
        /// <param name="loginDevice">登录设备</param>
        /// <param name="clientVersion">客户端版本</param>
        /// <returns></returns>
        public async Task <OperationResult> Login(string phoneNo, string password, string registKey, LoginDevice loginDevice, string clientVersion)
        {
            phoneNo.CheckNotNullOrEmpty("phoneNo");
            phoneNo.CheckNotNullOrEmpty("password");

            SysUser sUser = await UserManager.FindByNameAsync(phoneNo);

            var result = await UserManager.CheckPasswordAsync(sUser, password);

            if (!await UserManager.CheckPasswordAsync(sUser, password))
            {
                return(new OperationResult(OperationResultType.ValidError, "用户名或密码错误", null));
            }
            else
            {
                //更新最后一次登录的RegistKey
                var theUser = await UserInfos.SingleOrDefaultAsync(p => p.SysUser.PhoneNumber == phoneNo);

                if (theUser.RegistKey != registKey)
                {
                    theUser.RegistKey = registKey;
                    await UserInfoRepo.UpdateAsync(theUser);
                }

                //变更登录信息
                await ResetToken(theUser, loginDevice, clientVersion);

                var loginInfo = new UserTokenDto()
                {
                    Id       = theUser.Id,
                    NickName = theUser.SysUser.NickName,
                    HeadPic  = theUser.HeadPic,
                    Token    = theUser.Token
                };
                return(new OperationResult(OperationResultType.Success, "登录成功", loginInfo));
            }
        }
Beispiel #31
0
        /// <summary>
        /// 保存FeedBack信息(新增/更新)
        /// </summary>
        /// <param name="updateForeignKey">更新时是否更新外键信息</param>
        /// <param name="dtos">要保存的FeedBackDto信息</param>
        /// <returns>业务操作集合</returns>
        public async Task <OperationResult> SaveFeedBacks(bool updateForeignKey = false, params FeedBackDto[] dtos)
        {
            try
            {
                dtos.CheckNotNull("dtos");
                var addDtos    = dtos.Where(p => p.Id == 0).ToArray();
                var updateDtos = dtos.Where(p => p.Id != 0).ToArray();

                FeedBackRepo.UnitOfWork.TransactionEnabled = true;

                Action <FeedBackDto> checkAction = null;
                Func <FeedBackDto, FeedBack, FeedBack> updateFunc = (dto, entity) =>
                {
                    if (dto.Id == 0 || updateForeignKey)
                    {
                        entity.UserInfo = UserInfoRepo.GetByKey(dto.UserInfoId);
                    }
                    return(entity);
                };
                if (addDtos.Length > 0)
                {
                    FeedBackRepo.Insert(addDtos, checkAction, updateFunc);
                }
                if (updateDtos.Length > 0)
                {
                    FeedBackRepo.Update(updateDtos, checkAction, updateFunc);
                }
                await FeedBackRepo.UnitOfWork.SaveChangesAsync();

                return(new OperationResult(OperationResultType.Success, "保存成功"));
            }
            catch (Exception e)
            {
                return(new OperationResult(OperationResultType.Error, e.Message));
            }
        }
Beispiel #32
0
 /// <summary>
 /// 删除UserInfo信息
 /// </summary>
 /// <param name="ids">要删除的Id编号</param>
 /// <returns>业务操作结果</returns>
 public async Task <OperationResult> DeleteUserInfos(params int[] ids)
 {
     ids.CheckNotNull("ids");
     return(await Task.Run(() => UserInfoRepo.Delete(ids)));
 }
Beispiel #33
0
 public AvatarService()
 {
     _avatarRepo = DIService.GetSingleton<AvatarRepo>();
     _userInfoRepo = DIService.GetSingleton<UserInfoRepo>();
 }
 public UserInfoService()
 {
     _apiSettings = DIService.GetSingleton<ApiSettings>();
     _sessionInfoRepo = DIService.GetSingleton<SessionInfoRepo>();
     _userInfoRepo = DIService.GetSingleton<UserInfoRepo>();
 }