Esempio n. 1
0
        public ActionResult ActiveEmail(string t, string u)
        {
            string msg = "";

            if (t.IsNullOrEmpty() || u.IsNullOrEmpty())
            {
                msg = "参数为空,你是要搞事情啊";
            }
            else
            {
                string emailByToken = _iredisHelper.StringGet(t);
                int?   userId       = _iredisHelper.StringGet <int?>(u);

                if (emailByToken.IsNullOrEmpty() || userId == null)
                {
                    msg = "你这token都已经过期了,我可是给了你1个小时的时间。。。再去拿token吧。";
                }
                else
                {
                    _appUserRepository.Update(_appUserRepository.Queryable(r => r.Email == emailByToken && r.Id == userId), r => new AppUser
                    {
                        Email        = emailByToken,
                        EmailIsValid = true
                    });
                    msg = "您已成功验证该邮箱,你可以用这个邮箱登录系统了!";
                    _iredisHelper.KeyDeleteAsync(t);
                    _iredisHelper.KeyDeleteAsync(u);
                }
            }

            ViewBag.Msg = msg;

            return(View());
        }
Esempio n. 2
0
        /// <summary>
        /// 使用session暂存登录用户信息
        /// </summary>
        /// <param name="userEntity"></param>
        public void SaveUserSession(AppUser userEntity)
        {
            OperatorProvider op = OperatorProvider.Provider;

            bool isSystem = this.IsSystem(userEntity.Id);

            //保存用户信息
            op.CurrentUser = new OperatorModel
            {
                UserId          = userEntity.Id,
                IsSystem        = isSystem,
                IsAdmin         = userEntity.LoginName == "admin"?true:false,
                LoginName       = userEntity.LoginName,
                LoginToken      = Guid.NewGuid().ToString(),
                UserCode        = "1234",
                LoginTime       = DateTime.Now,
                NickName        = userEntity.NickName,
                Avatar          = userEntity.Avatar,
                Email           = userEntity.Email,
                PersonalWebsite = userEntity.PersonalWebsite
            };
            //缓存存放单点登录信息
            ICache cache = CacheFactory.Cache();

            op.Session[userEntity.Id.ToString()] = userEntity.LoginName;//必须使用这个存储一下session,否则sessionid在每一次请求的时候,都会为变更
            cache.WriteCache <string>(userEntity.Id.ToString(), op.Session.SessionID, DateTime.UtcNow.AddMinutes(60));

            //登录权限分配,根据用户Id获取用户所拥有的权限,可以在登录之后的Home界面中统一获取。

            _iRedisHelper.KeyDeleteAsync(string.Format(ConstHelper.AppModule, "AuthorizeUrl_" + userEntity.Id));
        }
Esempio n. 3
0
        public async Task StringTestAsync()
        {
            const string key   = "name";
            const string value = "colin";

            Assert.True(await _redis.StringSetAsync(key, value));
            Assert.Equal(value, await _redis.StringGetAsync <string>(key));
            Assert.Null(await _redis.StringGetAsync <string>("not_exist"));

            const string objKey = "person";
            var          people = new People("colin", 18);

            Assert.True(await _redis.StringSetAsync("person", people));
            Assert.Equal(people, await _redis.StringGetAsync <People>(objKey), new PeopleComparer());

            Assert.Equal(2, await _redis.KeyDeleteAsync(new[] { key, objKey }));
        }
Esempio n. 4
0
        /// <summary>
        /// 修改email,需要上次缓存的验证码和token
        /// </summary>
        /// <param name="email"></param>
        /// <param name="emailToken"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public ActionResult SetEmail(string email, string emailToken, string code)
        {
            if (code.IsNullOrEmpty())
            {
                return(Error("验证码不能为空"));
            }
            if (emailToken.IsNullOrEmpty())
            {
                return(Error("邮件标识符异常,请重新获取验证码!"));
            }

            string emailByToken = _redisHelper.StringGet(emailToken);

            if (emailByToken.IsNullOrEmpty())
            {
                return(Error("您的操作已过期,请重试!"));
            }

            if (emailByToken.IsNullOrEmpty() || !email.Equals(emailByToken))
            {
                return(Error("邮箱参数异常"));
            }
            string codeNew = _redisHelper.StringGet(emailToken + email);

            if (codeNew.IsNullOrEmpty())
            {
                return(Error("您的操作已过期,请重试!"));
            }

            if (!codeNew.Equals(code))
            {
                return(Error("您输入的验证码不正确,请重试!"));
            }

            _appUserRepository.Update(_appUserRepository.Queryable(u => u.Id == Op.CurrentUser.UserId), u => new AppUser
            {
                Email        = email,
                EmailIsValid = true
            });
            _redisHelper.KeyDeleteAsync(emailToken);
            _redisHelper.KeyDeleteAsync(emailToken + email);

            return(Success("绑定成功!"));
        }