Exemplo n.º 1
0
        /// <summary>
        /// Use this is to register new yousers
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <exception cref="ArgumentNullException">If request is null</exception>
        /// <exception cref="ArgumentException">If email not exist</exception>
        /// <returns></returns>
        public async override Task <TokenReply> HandleRequest(RequestObject <RegistrationRequest, TokenReply> request,
                                                              CancellationToken cancellationToken = default)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (request == null)
            {
                request = new RequestObject <RegistrationRequest, TokenReply>(new RegistrationRequest())
                {
                    StatusCode = StatusCode.NotFound
                };
                request.Detail = $"{nameof(request)} is null";
                return(new TokenReply());
            }

            RegistrationRequest requestData = request.Value;

            if (IsAccountExist(requestData.Email))
            {
                request.StatusCode = StatusCode.AlreadyExists;
                request.Detail     = "Email already exist";
                return(new TokenReply());
            }

            // this code work in only in valid satate

            string nickname = NicknameGenerator.FromEmail(requestData.Email);

            AccountRegistration accountRegistration = new AccountRegistration(requestData.Email, requestData.Password, nickname);

            Context.Accounts.Add(accountRegistration.Account);

            await Context.SaveChangesAsync();

            if (!requestData.IsAnonymous)
            {
                // send verifier email
                await emailVerifierService
                .InstatiateVerifierMessage(accountRegistration.Account.User, accountRegistration.Account.Email)
                .ConfigureAwait(false);
            }

            // generate token
            TokenResponse tokenResponse     = new TokenResponse(accountRegistration.Account.AccountId, accountRegistration.Account.Role, jwtProvider);
            TokenReply    registrationReply = new TokenReply
            {
                UserId = tokenResponse.UserId,
                Token  = tokenResponse.Token
            };

            return(registrationReply);
        }
Exemplo n.º 2
0
    private void OnEnable()
    {
        Spawner         = Spawner.Singletone;
        gameObject.name = NicknameGenerator.GenerateOneWordNick();

        CurrentDirVec   = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
        currentBehavior = Behavior.Passive;

        _peopleFinder = Instantiate(peopleFinderFab, transform.position, Quaternion.identity).GetComponent <PeopleFinder>();
        _peopleFinder.SetParent(transform);
        nearPeoplePosition = _peopleFinder.FindNearestObject();
    }
Exemplo n.º 3
0
        public AccountRegistration(string email, string password, string nickName = "")
        {
            passwordSalter = new SaltGenerator();
            if (string.IsNullOrEmpty(nickName))
            {
                nickName = NicknameGenerator.FromEmail(email);
            }

            Account = new Account()
            {
                Email            = email,
                Hash             = passwordSalter.SaltPassword(password),
                Role             = RoleType.Unverified,
                RegistrationDate = DateTime.UtcNow
            };
            Account.User = new User
            {
                NickName   = nickName,
                Experience = 0
            };
        }