コード例 #1
0
ファイル: UserController.cs プロジェクト: Lifeng-Liang/Blog
        public string SendActiveMail()
        {
            var u = this.GetLoginUser();

            if (u.Role == UserRole.NonactivatedUser)
            {
                var uv = UserValidate.FindOne(p => p.UserId == u.Id);
                if (uv == null)
                {
                    uv = new UserValidate().Init(u.Id);
                    uv.Save();
                }
                uv.Mode = 'a';
                SendMail(u, uv);
                Flash.Notice = "激活邮件发送成功";
            }
            return(UrlTo <UserController>(p => p.Profile()));
        }
コード例 #2
0
ファイル: UserController.cs プロジェクト: Lifeng-Liang/Blog
        public string Register()
        {
            var now = DateTime.Now;

            if (!BlogSettings.AllowRegister)
            {
                RegError("暂时不允许注册", now);
                return(null);
            }
            var  email    = Bind("email");
            var  password = Bind("password");
            var  showname = Bind("showname");
            var  time     = Bind("time");
            var  validate = Bind("validate");
            long ticks;

            if (email.LikeNull() || password.LikeNull() || showname.LikeNull() || email.IndexOf("@") < 0 ||
                !long.TryParse(time, out ticks) || validate.LikeNull())
            {
                RegError("Email密码以及显示名都是必填项", now);
                return(null);
            }
            var regTime = new DateTime(ticks);

            if (Math.Abs((now - regTime).TotalSeconds) > BlogSettings.RegTimeDiffSecs)
            {
                RegError("注册超时,请刷新后重新注册", now);
                return(null);
            }
            var realValidate = Base32StringCoding.Decode(StringHelper.HashMd5(BlogSettings.RegSolt + time));

            if (validate != realValidate)
            {
                Logger.Default.Trace("validate: " + validate + " - realValidate: " + realValidate + " - time: " + time);
                RegError("注册错误,请联系管理员", now);
                return(null);
            }
            if (password.Length >= 100)
            {
                return(null);
            }
            var u = new User
            {
                Email     = email,
                Password  = password,
                ShowName  = showname,
                Role      = UserRole.NonactivatedUser,
                SessionId = Guid.NewGuid().ToString()
            };
            var v = u.Validate();

            if (v.IsValid)
            {
                u.Save();
                var uv = new UserValidate().Init(u.Id);
                uv.Mode = 'a';
                uv.Save();

                SendMail(u, uv);

                Flash.Notice = "用户创建成功";
                return(UrlTo <UserController>(p => p.Login()));
            }
            var sb = new StringBuilder();

            foreach (var message in v.ErrorMessages)
            {
                sb.Append(message);
            }
            RegError(sb.ToString(), now);
            return(null);
        }