public async Task <IActionResult> AddAccount([FromBody] CreateAccount.Request request)
        {
            request.ActionBy = UserId.GetValueOrDefault();

            var result = await Mediator.Send(request);

            return(Respond(result));
        }
Beispiel #2
0
        public async Task <IActionResult> CreateAccount([FromBody] CreateAccount.Request req, [FromServices] AuthDBContext authDB)
        {
            var account = await authDB.Accounts.FindAsync(req.account);

            if (account != null)
            {
                return(Ok(new CreateAccount.Response
                {
                    resultCode = ProtocolModels.Auth.CreateAccount.Response.ResultCode.AlreadyExists,
                }));
            }

            var accountNew = new Account();

            accountNew.account  = req.account;
            accountNew.nickname = req.nickname;
            var salt = new byte[16];

            new RNGCryptoServiceProvider().GetBytes(salt);
            accountNew.hashedPassword = evolib.Util.Hasher.ToPbkdf2(req.password, salt);
            accountNew.salt           = Convert.ToBase64String(salt);
            accountNew.permission     = new evolib.Permission().Value;
            accountNew.hostType       = evolib.HostType.Player;
            await authDB.Accounts.AddAsync(accountNew);

            await authDB.SaveChangesAsync();

            return(Ok(new CreateAccount.Response
            {
                resultCode = ProtocolModels.Auth.CreateAccount.Response.ResultCode.Ok,
                account = accountNew.account,
                nickname = accountNew.nickname,
                permission = accountNew.permission,
                hostType = accountNew.hostType,
            }));
        }