Beispiel #1
0
        public Account CreateAccount(string userName, string password, string email, ClientBoxLevel boxLevel = ClientBoxLevel.Cataclysm,
                                     ClientLocale locale = ClientLocale.English)
        {
            Contract.Requires(!string.IsNullOrEmpty(userName));
            Contract.Requires(userName.Length >= Constants.Accounts.MinNameLength);
            Contract.Requires(userName.Length <= Constants.Accounts.MaxNameLength);
            Contract.Requires(!string.IsNullOrEmpty(password));
            Contract.Requires(password.Length >= Constants.Accounts.MinPasswordLength);
            Contract.Requires(password.Length <= Constants.Accounts.MaxPasswordLength);
            Contract.Requires(!string.IsNullOrEmpty(email));
            Contract.Ensures(Contract.Result <Account>() != null);

            var pw   = CreatePassword(userName, password);
            var sha1 = pw.SHA1Password.GetBytes();

            Contract.Assume(sha1.Length == Password.SHA1Length);
            var sha256 = pw.SHA256Password.GetBytes();

            Contract.Assume(sha256.Length == Password.SHA256Length);

            var rec = new AccountRecord(userName, email, sha1, sha256, boxLevel, locale);

            rec.Create();

            var acc = new Account(rec);

            AddAccount(acc);
            return(acc);
        }
Beispiel #2
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (_accountService.Exist(model.Account))
            {
                ModelState.AddModelError(string.Empty, "账号已经存在,请换一个试试。");
                return(View(model));
            }
            var user = UserRecord.Create(model.UserName, AccountRecord.Create(model.Account, model.Password));

            _userService.Create(user);

            return(RedirectToAction("SignIn"));
        }
Beispiel #3
0
        public override void Up()
        {
            Create
            .Table(TableName <AccountRecord>())
            .WithColumn("Id").AsAnsiString(32).PrimaryKey()
            .WithColumn("Account").AsString(20)
            .WithColumn("Password").AsString(50);

            Create
            .Table(TableName <UserRecord>())
            .WithColumn("Id").AsAnsiString(32).PrimaryKey()
            .WithColumn("Name").AsString(20)
            .WithColumn("Account_Id").AsAnsiString(32).ForeignKey(TableName <AccountRecord>(), "Id").OnDelete(Rule.Cascade);

            var account = AccountRecord.Create("admin", "admin");
            var user    = UserRecord.Create("admin", account);

            Insert.IntoTable(TableName <AccountRecord>()).Row(new { account.Id, account.Account, account.Password });
            Insert.IntoTable(TableName <UserRecord>()).Row(new { user.Id, user.Name, Account_Id = user.Account.Id });
        }