Пример #1
0
        public async Task <IActionResult> Login(string username, string password)
        {
            using (var conn = Account.GetAuthDb())
            {
                var query = await conn.QueryAsync <Account>(
                    "SELECT * FROM `pomelo_account`" +
                    "WHERE `username` = @username", new { username });

                var user = query.SingleOrDefault();

                if (user == null)
                {
                    return(Prompt(x =>
                    {
                        x.Title = "登录失败";
                        x.Details = $"用户{username}不存在";
                        x.StatusCode = 404;
                    }));
                }

                var validate = SHA256.Validate(username, password, user.Salt, user.Hash);
                if (!validate)
                {
                    return(Prompt(x =>
                    {
                        x.Title = "登录失败";
                        x.Details = $"用户名或密码不正确";
                        x.StatusCode = 400;
                    }));
                }

                // Set default character
                if (user.DefaultRealm.HasValue)
                {
                    var character = await CharacterCollector.GetCharacterAsync(user.DefaultRealm.Value, user.DefaultCharacter.Value);

                    if (character.AccountId != user.Id)
                    {
                        await SetDefaultCharacterAsync(user.Id, conn);
                    }
                    else
                    {
                        await SetDefaultCharacterAsync(user.Id, character.RealmId,
                                                       character.Id, character.Name, character.Race, character.Class,
                                                       character.Level, conn);
                    }
                }
                else
                {
                    await SetDefaultCharacterAsync(user.Id, conn);
                }

                HttpContext.Session.SetString("user", user.Username);
                return(RedirectToAction("Index"));
            }
        }
Пример #2
0
 public async Task <IActionResult> Index(uint realmId, uint characterId)
 {
     using (var conn = Account.GetAuthDb())
     {
         var character = await CharacterCollector.GetCharacterAsync(realmId, characterId);
         await SetDefaultCharacterAsync(
             Account.Id,
             realmId,
             characterId,
             character.Name,
             character.Race,
             character.Class,
             character.Level,
             conn);
     }
     return(Prompt(x =>
     {
         x.Title = "切换成功";
         x.Details = "您已经成功切换至新角色";
         x.HideBack = true;
         x.RedirectText = "刷新";
         x.RedirectUrl = Url.Action("Index");
     }));
 }