public async Task <IActionResult> SignUp([FromBody] RegistrationApiModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var entity = await _service.AddForAuthAsync(model);

                var resultModel = await _service.AuthenticateAsync(entity, model.Password, model.Remember);

                if (resultModel.ResultStatus == ResultStatusEnum.Failed)
                {
                    return(Unauthorized());
                }

                return(Ok(resultModel));
            }
            catch (DuplicateNameException ex)
            {
                return(StatusCode(405, ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Example #2
0
        public async Task <HeroGetFullApiModel> AddAsync(RegistrationApiModel model)
        {
            var entity = await CreateEntityAsync(model.Hero, model.Password);

            var modelResult = _dataAdapter.Parse <HeroEntity, HeroGetFullApiModel>(entity);

            return(modelResult);
        }
Example #3
0
        public async Task <ActionResult <SignInApiModel> > Registration(RegistrationApiModel model)
        {
            var user = await _service.RegistrationAsync(model.Login, model.Password, model.ContactType, model.UserProfile ?? new UserProfileAddApiModel());

            var signIn = await _service.GenerateSignInResponseAsync(user);

            return(SuccessResult(signIn));
        }
Example #4
0
        public async Task <ActionResult <SignInApiModel> > RegistrationEmail(RegistrationApiModel model)
        {
            var user = await _service.Registration(model.Login, model.Password, model.UserName, UserContactTypeEnum.email,
                                                   model.UserProfile ?? new UserProfileAddApiModel());

            var signIn = await GetTokenApiModel(user);

            await BroadcastMessageSignalR(NotificationTypeEnum.ModelAdd, user, true, user.Id);

            return(SuccessResult(signIn));
        }
Example #5
0
        public async Task <IActionResult> Post([FromBody] RegistrationApiModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdentity = _mapper.Map <IdentityAppUser>(model);

            var result = await _userManager.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState)));
            }

            await _appDbContext.EmosUsers.AddAsync(new EmosUser { IdentityId = userIdentity.Id });

            await _appDbContext.SaveChangesAsync();

            return(new OkObjectResult("Account created"));
        }
Example #6
0
        public async Task <HeroEntity> AddForAuthAsync(RegistrationApiModel model)
        {
            var entity = await CreateEntityAsync(model.Hero, model.Password);

            return(entity);
        }