Beispiel #1
0
        public async Task <IActionResult> RegisterDemo([FromBody] RegisterDemoViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(GetModelStateErrorResponse(ModelState)));
            }

            var resp = await RegisterDemoUser(model);

            if (resp.Type != ResponseType.Success)
            {
                return(BadRequest(resp));
            }

            return(Ok(resp));
        }
Beispiel #2
0
        /// <summary>
        /// creates new user
        /// </summary>
        /// <param name="model"></param>
        private async Task <ApiResponse <string> > RegisterDemoUser(RegisterDemoViewModel model)
        {
            var apiResp = new ApiResponse <string>
            {
                Type = ResponseType.Fail
            };

            var id             = Guid.NewGuid();
            var username       = id.ToString("N");
            var now            = DateTime.UtcNow;
            var expirationDate = now.AddDays(15);

            var applicationUser = new ApplicationUser
            {
                Id             = id,
                Email          = username + "@d.com",
                Title          = model.Language == Language.Turkish ? "Demo A.Ş." : "Demo Corp.",
                UserName       = username,
                EmailConfirmed = true,
                Roles          = new List <string> {
                    DatabaseKeys.ApplicationRoleName.DemoUser
                },
                Settings            = _userBusiness.GetDefaultSettings(),
                CreatedAt           = now,
                MembershipExpiresAt = expirationDate
            };

            var resp = await _security.Register(applicationUser, model.Password);

            if (resp.Type != ResponseType.Success)
            {
                apiResp.ErrorCode = resp.ErrorCode;
                return(apiResp);
            }

            resp = _userBusiness.CreateDemoUserDefaultEntries(applicationUser.Id, model.Language);

            if (resp.Type != ResponseType.Success)
            {
                apiResp.ErrorCode = resp.ErrorCode;
                return(apiResp);
            }

            apiResp.Data = applicationUser.Email;
            apiResp.Type = ResponseType.Success;
            return(apiResp);
        }