예제 #1
0
        public PyStudioPromptData PyStudioPromptDatas()
        {
            var data = new PyStudioPromptData();

            data.Data = new { Id = 1, Name = "LX" };
            data.IsOK = 1;
            data.Msg  = "OK";
            return(data);
        }
예제 #2
0
        public async Task <JsonResult> SettingEmail(string email)
        {
            var data = new PyStudioPromptData();

            if (string.IsNullOrWhiteSpace(email))
            {
                data.IsOK = 2;
                data.Msg  = "请输入邮箱!";
                return(Json(data));
            }
            email = email.Trim();
            if (email.Length >= 50 || email.Length <= 3)
            {
                data.IsOK = 2;
                data.Msg  = "邮箱长度不符!";
                return(Json(data));
            }
            else if (!email.Contains("@"))
            {
                data.IsOK = 2;
                data.Msg  = "邮箱格式不正确!";
                return(Json(data));
            }
            var timeOut    = 30;
            var now        = DateTime.Now.AddMinutes(timeOut);
            var expires    = now.ToString("yyyy-MM-dd hh:mm:ss");
            var token      = $"{expires}-{email}-{Request.Host.Host}-{_MyUserInfo.UserId}"._Md5();
            var appUrl     = $"http://{Request.Host.Host}:{Request.Host.Port}";
            var comfirmUrl = $"{appUrl}/Admin/UserCenter/ConfirmSettingEmail?expire={expires}&token={token}&email={email}&t=0.9527{_MyUserInfo.UserId}";

            //读取邮箱模版
            var tpl = await ExtentionsClass._GetHtmlTpl(EmEmailTpl.SettingEmail, $"{_hostingEnvironment.WebRootPath}/{_pySelfSetting.EmailTplPath}");

            if (string.IsNullOrWhiteSpace(tpl))
            {
                data.IsOK = 0;
                data.Msg  = "发送绑定邮件失败,请稍后再试!";
                return(Json(data));
            }
            string name = _MyUserInfo.UserNickName;

            if (string.IsNullOrWhiteSpace(name))
            {
                name = _MyUserInfo.UserName;
            }
            tpl = tpl.Replace("{name}", name).Replace("{content}", $"您正在使用<a href='{appUrl}'>PyStudio交易网</a>邮箱绑定功能<a href='{comfirmUrl}'>{comfirmUrl}</a>;注意该地址有效时间{timeOut}分钟。");
            //发送
            var isOk = ExtentionsClass._SendEmail(new Dictionary <string, string> {
                { name, email }
            }, "PyStudio交易网", tpl);

            data.IsOK = isOk ? 1 : 0;
            data.Msg  = isOk ? "已给您邮箱发送了绑定确认邮件,请收件后点击确认绑定链接地址。" : "发送绑定邮件失败,请稍后重试!";

            return(Json(data));
        }
예제 #3
0
        public async Task <JsonResult> AreaInfoDelete(int id)
        {
            var pathId   = (from t1 in _context.InfoArea where t1.AreaId.Equals(id) select new { ThisPathId = t1.AreaPathId }).FirstOrDefault();
            var infoArea = _context.InfoArea.Where(t => t.AreaPathId.StartsWith(pathId.ThisPathId)).ToList();

            var data = new PyStudioPromptData();

            if (infoArea != null)
            {
                foreach (var item in infoArea)
                {
                    _context.InfoArea.Remove(item);
                }
                var result = await _context.SaveChangesAsync();

                if (result > 0)
                {
                    data.IsOK = 1;
                    data.Msg  = $"删除成功,共删除{result}条数据!";
                    string resultName = string.Empty;
                    for (int i = 0; i < infoArea.Count; i++)
                    {
                        resultName += infoArea[i].AreaName + ",";
                    }
                    _context.SysLogger.Add(new SysLogger
                    {
                        LoggerCreateTime  = DateTime.Now,
                        LoggerDescription = $"{EmLogStatus.删除}地区{resultName.TrimEnd(',')}",
                        LoggerIps         = _MyUserInfo.UserIps,
                        LoggerOperation   = (int)EmLogStatus.除,
                        LoggerUser        = _MyUserInfo.UserId
                    });
                    await _context.SaveChangesAsync();
                }
                else
                {
                    data.IsOK = 0;
                    data.Msg  = "删除失败!";
                }
            }
            else
            {
                data.IsOK = 2;
                data.Msg  = "未找到数据!";
            }
            return(Json(data));
        }
예제 #4
0
        public async Task <JsonResult> AreaInfoModify([Bind("AreaId,AreaPathId,AreaName,AreaCoord,AreaZipCode,AreaNote,UpAreaName,UpAreaPathId")] AreaInfo _areaInfo)
        {
            var data = new PyStudioPromptData();

            if (ModelState.IsValid)
            {
                var infoArea = _context.InfoArea.Where(b => b.AreaId.Equals(_areaInfo.AreaId) && b.AreaPathId.Equals(_areaInfo.AreaPathId)).FirstOrDefault();
                if (infoArea != null)
                {
                    infoArea.AreaName    = _areaInfo.AreaName;
                    infoArea.AreaCoord   = _areaInfo.AreaCoord;
                    infoArea.AreaZipCode = _areaInfo.AreaZipCode;
                    infoArea.AreaNote    = _areaInfo.AreaNote;
                    var result = await _context.SaveChangesAsync();

                    if (result > 0)
                    {
                        data.IsOK = 1;
                        data.Msg  = "修改成功";
                        _context.SysLogger.Add(new SysLogger
                        {
                            LoggerCreateTime  = DateTime.Now,
                            LoggerDescription = $"{EmLogStatus.修改}地区{infoArea.AreaName}信息",
                            LoggerIps         = _MyUserInfo.UserIps,
                            LoggerOperation   = (int)EmLogStatus.修改,
                            LoggerUser        = _MyUserInfo.UserId
                        });
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        data.IsOK = 0;
                        data.Msg  = "修改失败!请稍后再试...";
                    }
                }
                else
                {
                    data.IsOK = 0;
                    data.Msg  = "修改失败!请稍后再试...";
                }
            }
            return(Json(data));
        }
예제 #5
0
        public JsonResult GetLoginInfo()
        {
            var data     = new PyStudioPromptData();
            var userInfo = HttpContext.Session.Get <PyUserInfo>(HttpContext.Session.SessionKey());

            if (userInfo != null)
            {
                data.Data = userInfo;
                data.IsOK = 1;
            }
            if (data.IsOK.Equals(1))
            {
                data.Msg = "已登录";
            }
            else
            {
                data.Msg = "未登录";
            }
            return(Json(data));
        }
예제 #6
0
        public async Task <PyStudioPromptData> ForgetPassword(string email)
        {
            var data = new PyStudioPromptData();

            if (string.IsNullOrWhiteSpace(email))
            {
                data.IsOK = 2;
                data.Msg  = "请输入邮箱!";
                return(data);
            }

            email = email.Trim().ToLower();
            if (email.Length >= 50 || email.Length <= 3)
            {
                data.IsOK = 2;
                data.Msg  = "邮箱长度不符!";
                return(data);
            }
            else if (!email.Contains("@"))
            {
                data.IsOK = 2;
                data.Msg  = "邮箱格式不正确!";
                return(data);
            }


            var userInfo = await _context.InfoUser.SingleOrDefaultAsync(m => m.UserEmail.ToLower() == email);

            if (userInfo == null)
            {
                data.IsOK = 0;
                data.Msg  = "找不到绑定该邮箱的账号!";
                return(data);
            }
            else if (userInfo.UserStatus == (int)EmUserStatus.禁用)
            {
                data.IsOK = 0;
                data.Msg  = "该邮箱已被封禁,您可以通过发送邮件至:[email protected] 联系管理员!";
                return(data);
            }

            var timeOut    = 10;
            var now        = DateTime.Now.AddMinutes(timeOut);
            var expires    = now.ToString("yyyy-MM-dd hh:mm");
            var token      = $"{expires}-{email}-{Request.Host.Host}"._Md5();
            var appUrl     = $"http://{Request.Host.Host}:{Request.Host.Port}";
            var comfirmUrl = $"{appUrl}/Admin/Account/ConfirmPassword?expire={expires}&token={token}&={email}&t=0.{now.ToString("ssfff")}";

            //读取模版
            var tpl = await ExtentionsClass._GetHtmlTpl(EmEmailTpl.MsgBox, $"{_hostingEnvironment.WebRootPath}/{_selfSetting.EmailTplPath}");

            if (string.IsNullOrWhiteSpace(tpl))
            {
                data.IsOK = 0;
                data.Msg  = "发送绑定邮箱失败,请稍后重试。";
                return(data);
            }
            tpl = tpl.Replace("{name}", $"尊敬的用户{userInfo.UserNickName}")
                  .Replace("{content}", $"您正在使用 <a href = '{appUrl}'>PyStudio</a> 邮箱重置密码功能,请点击以下链接确认绑定邮箱 <a href = '{comfirmUrl}'>{ comfirmUrl}</a>;注意该地址有效时间{timeOut}分钟。");
            var isOk = ExtentionsClass._SendEmail(new Dictionary <string, string> {
                { $"尊敬的用户{userInfo.UserNickName}", email }
            }, "PyStudio - 重置密码", tpl);

            data.IsOK = isOk ? 1 : 0;
            data.Msg  = isOk ? "已给您邮箱发送了绑定确认邮件,请收件后点击确认绑定链接地址。" : "发送绑定邮件失败,请稍后重试!";

            return(data);
        }
예제 #7
0
        public async Task <JsonResult> Register([Bind("UserName,UserPwd,ComfirmPwd")] PyRegisterUser registerUser)
        {
            var data = new PyStudioPromptData();

            if (ModelState.IsValid)
            {
                #region 验证
                if (_context.InfoUser.Any(b => b.UserName.ToUpper().Equals(registerUser.UserName.Trim().ToUpper())))
                {
                    data.IsOK = 2;
                    data.Msg  = "已存在相同的账号!";
                    return(Json(data));
                }
                #endregion

                InfoUser infoUser = new InfoUser();
                infoUser.UserName       = registerUser.UserName.Trim();
                infoUser.UserNickName   = registerUser.UserName;
                infoUser.UserPwd        = registerUser.UserPwd.Trim()._Md5();
                infoUser.UserSex        = 3;
                infoUser.UserHeadPhoto  = "/images/default.png";
                infoUser.UserStatus     = (int)EmUserStatus.启用;
                infoUser.UserCreateTime = DateTime.Now;
                infoUser.UserIps        = this.GetUserIp();

                _context.Add(infoUser);

                var result = await _context.SaveChangesAsync();

                if (result > 0)
                {
                    data.IsOK = 1;
                    data.Msg  = "注册成功";
                    var _pyUserInfo = new PyUserInfo
                    {
                        UserId         = infoUser.UserId,
                        UserName       = infoUser.UserName,
                        UserNickName   = infoUser.UserNickName,
                        UserEmail      = infoUser.UserEmail,
                        UserTel        = infoUser.UserTel,
                        UserSex        = infoUser.UserSex,
                        UserIntroduce  = infoUser.UserIntroduce,
                        UserHeadPhoto  = infoUser.UserHeadPhoto,
                        UserBirthday   = infoUser.UserBirthday,
                        UserAddress    = infoUser.UserAddress,
                        UserBlog       = infoUser.UserBlog,
                        UserStatus     = infoUser.UserStatus,
                        UserCreateTime = infoUser.UserCreateTime,
                        UserLoginTime  = infoUser.UserLoginTime,
                        UserIps        = infoUser.UserIps
                    };
                    HttpContext.Session.Set <PyUserInfo>(HttpContext.Session.SessionKey(), _pyUserInfo);

                    #region 操作日志记录
                    _context.SysLogger.Add(new SysLogger
                    {
                        LoggerUser        = _pyUserInfo.UserId,
                        LoggerDescription = $"用户{_pyUserInfo.UserName} {EmLogStatus.注册} ",
                        LoggerOperation   = (int)EmLogStatus.注册,
                        LoggerCreateTime  = DateTime.Now,
                        LoggerIps         = _pyUserInfo.UserIps
                    });

                    _context.SysLogger.Add(new SysLogger
                    {
                        LoggerUser        = _pyUserInfo.UserId,
                        LoggerDescription = $"用户{_pyUserInfo.UserName} {EmLogStatus.登录} ",
                        LoggerOperation   = (int)EmLogStatus.登录,
                        LoggerCreateTime  = DateTime.Now,
                        LoggerIps         = _pyUserInfo.UserIps
                    });

                    await _context.SaveChangesAsync();

                    #endregion
                }
                else
                {
                    data.IsOK = 0;
                    data.Msg  = "注册失败!请联系客服";
                }
            }
            else
            {
                data.IsOK = 0;
                data.Msg  = "注册失败!请联系客服";
            }
            return(Json(data));
        }
예제 #8
0
        public async Task <JsonResult> Login([Bind("UserName,UserPwd,ReturnUrl")] PyLoginUser loginUser)
        {
            var data = new PyStudioPromptData();

            //if (ModelState.IsValid)
            //{
            var md5Pwd   = loginUser.UserPwd.Trim()._Md5();
            var userInfo = await _context.InfoUser.SingleOrDefaultAsync(b => b.UserName.Equals(loginUser.UserName, StringComparison.CurrentCultureIgnoreCase) && b.UserPwd.Equals(md5Pwd));

            if (userInfo == null)
            {
                data.IsOK = 2;
                data.Msg  = "用户名或密码错误!";
                return(Json(data));
            }
            else if (userInfo.UserStatus == (int)EmUserStatus.禁用)
            {
                data.IsOK = 2;
                data.Msg  = "该账号已被禁用,或许你可以重新注册一个账号或者联系管理员!";
                return(Json(data));
            }

            userInfo.UserIps       = this.GetUserIp();
            userInfo.UserLoginTime = DateTime.Now;

            var _pyUserInfo = new PyUserInfo
            {
                UserId         = userInfo.UserId,
                UserName       = userInfo.UserName,
                UserNickName   = userInfo.UserNickName,
                UserEmail      = userInfo.UserEmail,
                UserTel        = userInfo.UserTel,
                UserSex        = userInfo.UserSex,
                UserIntroduce  = userInfo.UserIntroduce,
                UserHeadPhoto  = userInfo.UserHeadPhoto,
                UserBirthday   = userInfo.UserBirthday,
                UserAddress    = userInfo.UserAddress,
                UserBlog       = userInfo.UserBlog,
                UserStatus     = userInfo.UserStatus,
                UserCreateTime = userInfo.UserCreateTime,
                UserLoginTime  = userInfo.UserLoginTime,
                UserIps        = userInfo.UserIps
            };

            HttpContext.Session.Set <PyUserInfo>(HttpContext.Session.SessionKey(), _pyUserInfo);

            _context.SysLogger.Add(new SysLogger
            {
                LoggerUser        = _pyUserInfo.UserId,
                LoggerDescription = $"用户{_pyUserInfo.UserName}{EmLogStatus.登录} ",
                LoggerOperation   = (int)EmLogStatus.登录,
                LoggerCreateTime  = DateTime.Now,
                LoggerIps         = _pyUserInfo.UserIps
            });

            await _context.SaveChangesAsync();

            data.IsOK = 1;
            data.Msg  = "登录成功";
            //}
            //else
            //{
            //    data.IsOK = 0;
            //    data.Msg = "登录失败!";
            //}
            return(Json(data));
        }
        public async Task <JsonResult> UpHeadPhoto([Bind("UserId")] PyUserInfo pyUserInfo)
        {
            var data = new PyStudioPromptData();
            var file = Request.Form.Files.Where(b => b.Name == "myHeadPhoto" && b.ContentType.Contains("image")).SingleOrDefault();

            if (file == null)
            {
                data.Msg  = "请选择要上传的图片!";
                data.IsOK = 2;
                return(Json(data));
            }
            var maxSize = 1024 * 1024 * 4;

            if (file.Length > maxSize)
            {
                data.Msg  = "头像大小不能大于4M!";
                data.IsOK = 2;
                return(Json(data));
            }
            var fileExtend  = file.FileName.Substring(file.FileName.LastIndexOf('.'));
            var fileNewName = $"{DateTime.Now.ToString("yyyyMMddhhmmssfff")}{fileExtend}";
            var path        = Path.Combine($"{_hostingEnvironment.WebRootPath}/{_pySelfSetting.HeadPhotoPath}", fileNewName);

            using (var stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                await file.CopyToAsync(stream);
            }

            var viewPath = $"{_pySelfSetting.HeadPhotoPath}/{fileNewName}";
            var user     = _context.InfoUser.Where(b => b.UserId == _MyUserInfo.UserId).SingleOrDefault();

            if (user == null)
            {
                data.Msg  = "上传失败,请稍后再试!";
                data.IsOK = 0;
                return(Json(data));
            }
            user.UserHeadPhoto = viewPath;
            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                _MyUserInfo.UserHeadPhoto = viewPath;
                HttpContext.Session.Set <PyUserInfo>(HttpContext.Session.SessionKey(), _MyUserInfo);
                data.Msg  = "上传成功!";
                data.IsOK = 1;
                _context.SysLogger.Add(new SysLogger
                {
                    LoggerUser        = _MyUserInfo.UserId,
                    LoggerDescription = $"用户{_MyUserInfo.UserName}{EmLogStatus.修改}头像",
                    LoggerOperation   = (int)EmLogStatus.修改,
                    LoggerCreateTime  = DateTime.Now,
                    LoggerIps         = this.GetUserIp()
                });
                await _context.SaveChangesAsync();
            }
            else
            {
                data.Msg  = "上传失败,请稍后再试!";
                data.IsOK = 0;
                return(Json(data));
            }

            return(Json(data));
        }
예제 #10
0
        public async Task <JsonResult> ModifyUserInfo([Bind("UserId,UserName,UserNickName,UserEmail,UserTel,UserIntroduce,UserBirthday,UserAddress,UserBlog")] PyUserInfo pyUserInfo)
        {
            var data = new PyStudioPromptData();

            if (ModelState.IsValid)
            {
                var userInfo = _context.InfoUser.Where(b => b.UserId.Equals(pyUserInfo.UserId)).FirstOrDefault();
                if (userInfo != null)
                {
                    userInfo.UserNickName  = pyUserInfo.UserNickName;
                    userInfo.UserEmail     = pyUserInfo.UserEmail;
                    userInfo.UserTel       = pyUserInfo.UserTel;
                    userInfo.UserIntroduce = pyUserInfo.UserIntroduce;
                    userInfo.UserBirthday  = pyUserInfo.UserBirthday;
                    userInfo.UserAddress   = pyUserInfo.UserAddress;
                    userInfo.UserBlog      = pyUserInfo.UserBlog;

                    _MyUserInfo.UserNickName  = pyUserInfo.UserNickName;
                    _MyUserInfo.UserEmail     = pyUserInfo.UserEmail;
                    _MyUserInfo.UserTel       = pyUserInfo.UserTel;
                    _MyUserInfo.UserIntroduce = pyUserInfo.UserIntroduce;
                    _MyUserInfo.UserBirthday  = pyUserInfo.UserBirthday;
                    _MyUserInfo.UserAddress   = pyUserInfo.UserAddress;
                    _MyUserInfo.UserBlog      = pyUserInfo.UserBlog;

                    var result = await _context.SaveChangesAsync();

                    if (result > 0)
                    {
                        HttpContext.Session.Set <PyUserInfo>(HttpContext.Session.SessionKey(), _MyUserInfo);
                        _MyUserInfo = HttpContext.Session.Get <PyUserInfo>(HttpContext.Session.SessionKey());

                        data.IsOK = 1;
                        data.Msg  = "修改成功";
                        _context.SysLogger.Add(new SysLogger
                        {
                            LoggerUser        = _MyUserInfo.UserId,
                            LoggerDescription = $"用户{_MyUserInfo.UserName}{EmLogStatus.修改}个人信息",
                            LoggerOperation   = (int)EmLogStatus.修改,
                            LoggerCreateTime  = DateTime.Now,
                            LoggerIps         = this.GetUserIp()
                        });
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        data.IsOK = 0;
                        data.Msg  = "修改失败!请稍后再试...";
                        return(Json(data));
                    }
                }
                else
                {
                    data.IsOK = 0;
                    data.Msg  = "修改失败!请稍后再试...";
                    return(Json(data));
                }
            }
            else
            {
                data.IsOK = 0;
                data.Msg  = "修改失败!请稍后再试...";
                return(Json(data));
            }
            return(Json(data));
        }