Пример #1
0
        public async Task <IServiceResult> SignupAsync(SignupBindingModel signupModel)
        {
            var username   = _randomMaker.NewNumber();
            var duplicated = await FirstAsync(new AccountGetFirstSchema { Username = username });

            while (duplicated != null)
            {
                username   = _randomMaker.NewNumber();
                duplicated = await FirstAsync(new AccountGetFirstSchema { Username = username });
            }

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) {
                try {
                    var now = DateTime.UtcNow;

                    var account = new AccountAddSchema {
                        Password   = _cryptograph.RNG(signupModel.Password),
                        ProviderId = AccountProvider.Clipboardy.ToInt(),
                        Username   = username,
                        CreatedAt  = now,
                        StatusId   = Status.Active.ToInt()
                    };
                    var accountId = await AddAsync(account);

                    var accountDevice = new AccountDeviceAddSchema {
                        AccountId  = accountId,
                        DeviceId   = signupModel.DeviceId,
                        DeviceName = signupModel.DeviceName,
                        DeviceType = signupModel.DeviceType,
                        CreatedAt  = now,
                        StatusId   = Status.Active.ToInt()
                    };
                    var deviceId = await _accountDeviceService.AddAsync(accountDevice);

                    var accountProfile = new AccountProfileAddSchema {
                        AccountId = accountId,
                        LinkedId  = string.IsNullOrWhiteSpace(signupModel.Email) ? signupModel.Phone : signupModel.Email,
                        TypeId    = string.IsNullOrWhiteSpace(signupModel.Email) ? AccountProfileType.Phone.ToInt() : AccountProfileType.Email.ToInt(),
                        CreatedAt = now,
                        StatusId  = Status.Active.ToInt()
                    };
                    await _accountProfileService.AddAsync(accountProfile);

                    transaction.Complete();

                    var token = _jwtHandler.Bearer(new Account(accountId, deviceId, username, now).ToClaimsIdentity());
                    return(DataTransferer.Ok(token));
                }
                catch (Exception ex) {
                    var errmsg = "Something went wrong.";
                    Log.Error(ex, errmsg);
                    return(DataTransferer.InternalServerError(ex));
                }
            }
        }
Пример #2
0
        public async Task <IServiceResult> ExternalSignupAsync(ExternalUserBindingModel externalUser)
        {
            var username   = _randomMaker.NewNumber();
            var duplicated = await FirstAsync(new AccountGetFirstSchema { Username = username });

            while (duplicated != null)
            {
                username   = _randomMaker.NewNumber();
                duplicated = await FirstAsync(new AccountGetFirstSchema { Username = username });
            }

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) {
                try {
                    var now = DateTime.UtcNow;

                    var account = new AccountAddSchema {
                        ProviderId = externalUser.ProviderId.ToInt(),
                        Username   = username,
                        CreatedAt  = now,
                        StatusId   = Status.Active.ToInt()
                    };
                    var accountId = await AddAsync(account);

                    var accountDevice = new AccountDeviceAddSchema {
                        AccountId  = accountId,
                        DeviceId   = externalUser.DeviceId,
                        DeviceName = externalUser.DeviceName,
                        DeviceType = externalUser.DeviceType,
                        CreatedAt  = now,
                        StatusId   = Status.Active.ToInt()
                    };
                    var deviceId = await _accountDeviceService.AddAsync(accountDevice);

                    var accountProfile = new AccountProfileAddSchema {
                        AccountId = accountId,
                        TypeId    = AccountProfileType.Email.ToInt(),
                        LinkedId  = externalUser.Email,
                        CreatedAt = now,
                        StatusId  = Status.Active.ToInt()
                    };
                    await _accountProfileService.AddAsync(accountProfile);

                    transaction.Complete();
                    var token = _jwtHandler.Bearer(new Account(accountId, deviceId, username, now).ToClaimsIdentity());
                    return(DataTransferer.Ok(token));
                }
                catch (Exception ex) {
                    var errmsg = "Something went wrong.";
                    Log.Error(ex, errmsg);
                    return(null);
                }
            }
        }
        public void Add()
        {
            var accountProfile = new AccountProfileAddSchema {
                AccountId = 8,
                TypeId    = AccountProfileType.Email.ToInt(),
                LinkedId  = "*****@*****.**",
                CreatedAt = DateTime.Now,
                StatusId  = Status.Active.ToInt()
            };
            var accountProfileId = _accountProfileService.AddAsync(accountProfile).GetAwaiter().GetResult();

            Assert.IsTrue(accountProfile.StatusCode == 200);
            Assert.IsTrue(accountProfileId > 0);
        }
Пример #4
0
        public async Task <int> AddAsync(AccountProfileAddSchema accountProfile)
        {
            var result = await _storedProcedure.ExecuteScalarAsync <AccountProfileAddSchema, int>(accountProfile);

            return(result);
        }