示例#1
0
        private JsonResult GetToken(LoginOutput output)
        {
            var token = _userToken.Create(new[]
            {
                new Claim(LoginUserDto.Id.ToString(), output.Id.ToString()),
                new Claim(LoginUserDto.Account, output.Account),
                new Claim(LoginUserDto.RealName, output.RealName),
            });

            return(Result(new { token }));
        }
示例#2
0
        public ActionResult ForgetPassword(string email)
        {
            //ViewBag.Token = token;
            //if (string.IsNullOrEmpty(token))
            //{
            //    return new HttpNotFoundResult();
            //}
            if (string.IsNullOrEmpty(email))
            {
                ModelState.AddModelError("", "邮箱不能为空");
                return(View());
            }

            PaginationInfo paging = new PaginationInfo();
            IList <User>   users  = iuser.Get(null, null, null, null, email, null, null, null, null, null, 1, 0, null, out paging);

            if (users == null || users.Count == 0)
            {
                ModelState.AddModelError("", "系统不存在该邮箱");
                return(View());
            }

            string msgcontent    = "<html>  <head><base target='_blank'></head>  <body style='margin-bottom: 0px; margin-top: 0px; padding-bottom: 0px; padding-top: 0px; '>          <p>         请点击以下链接来重置你的密码:          </p>            <p>          <a href='{0}/account/resetpassword?token={1}' target='_blank'>{0}/account/resetpassword?token={1}</a>          </p>  </body></html>";
            string emailaccount  = System.Configuration.ConfigurationManager.AppSettings["emailaccount"];
            string emailpassword = System.Configuration.ConfigurationManager.AppSettings["emailpassword"];
            string smtp          = System.Configuration.ConfigurationManager.AppSettings["smtp"];
            string port          = System.Configuration.ConfigurationManager.AppSettings["port"];
            string domain        = System.Configuration.ConfigurationManager.AppSettings["domain"];
            Guid   token         = Guid.NewGuid();
            bool   issuc         = Beauty.Common.Helper.SendEmail(emailaccount, emailpassword, smtp, port, users[0].Email, "美丽说分享宝重置密码", string.Format(msgcontent, domain, token.ToString()));

            if (issuc)
            {
                Guid id = iusertoken.Create(new UserToken {
                    ID = token, Userid = users[0].ID, Statues = 1
                });
                if (id == token)
                {
                    WriteLog(users[0].Username + " 激活邮件发送成功");
                    AddCrossActionMsg("OK", "激活邮件发送成功!");
                }
                else
                {
                    AddCrossActionMsg("Fail", "激活邮件发送失败!");
                }
            }
            else
            {
                AddCrossActionMsg("Fail", "激活邮件发送失败!");
            }

            return(View());
        }
示例#3
0
 /// <summary>
 /// 获取Token
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public Task <TokenOutput> TokenAsync(LoginInput input)
 {
     Claim[] claims =
     {
         new Claim(UserOptions.UserId,   "001"),
         new Claim(UserOptions.Role,     "admin"),
         new Claim(UserOptions.DBName,   input.DbName),
         new Claim(UserOptions.UserName, input.UserName)
     };
     return(Task.FromResult(new TokenOutput {
         Token = _userToken.Create(claims)
     }));
 }
示例#4
0
        public void CreateTest()
        {
            Claim[] claims =
            {
                new Claim(UserOptions.UserId,   "001"),
                new Claim(UserOptions.Role,     "admin"),
                new Claim(UserOptions.DBName,   "zxsccore"),
                new Claim(UserOptions.UserName, "admin")
            };
            var token = _userToken.Create(claims);

            claims = _userToken.Decode(token);
            Assert.IsNotNull(claims);
            Assert.IsTrue(claims.Any());
        }
示例#5
0
        /// <summary>
        /// 获得token
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        private IResultModel GetToken(ResultModel <AuthLoginOutput> output)
        {
            if (!output.Success)
            {
                return(ResultModel.Failed(output.Msg));
            }

            var user = output.Data;

            output.Data.AccessToken = _userToken.Create(new[]
            {
                new Claim(ClaimAttributes.UserId, user.Id.ToString()),
                new Claim(ClaimAttributes.UserName, user.UserName),
                new Claim(ClaimAttributes.UserNickName, user.NickName)
            });
            return(output);
        }
示例#6
0
        /// <summary>
        /// 获得token
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        private IResponseOutput GetToken(ResponseOutput <AuthLoginOutput> output)
        {
            if (!output.Success)
            {
                return(ResponseOutput.NotOk(output.Msg));
            }

            var user  = output.Data;
            var token = _userToken.Create(new[]
            {
                new Claim(ClaimAttributes.UserId, user.Id.ToString()),
                new Claim(ClaimAttributes.UserName, user.UserName),
                new Claim(ClaimAttributes.UserNickName, user.NickName)
            });

            return(ResponseOutput.Ok(new { token }));
        }