Exemplo n.º 1
0
        public async Task <IActionResult> Login(UserLoginDto userLoginDto)
        {
            if (!RequestValidation.IsRequestValid <UserLoginDto>(userLoginDto))
            {
                return(BadRequest("Invalid request"));
            }

            var user = await userManager.FindByEmailAsync(userLoginDto.Email);

            if (user == null)
            {
                return(Unauthorized());
            }

            var result = await signInManager.CheckPasswordSignInAsync(user, userLoginDto.Password, false);

            if (result.Succeeded)
            {
                var appUser = mapper.Map <UserForListDto>(user);
                return(Ok(new
                {
                    token = service.GenerateJwtToken(user, userManager, config).Result,
                    user = appUser
                }));
            }
            return(Unauthorized());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto)
        {
            if (!RequestValidation.IsRequestValid <UserForRegisterDto>(userForRegisterDto))
            {
                return(BadRequest("Invalid request"));
            }

            var newUser = mapper.Map <User>(userForRegisterDto);

            newUser.Blog = new Blog
            {
                BlogName = userForRegisterDto.BlogName,
                Author   = newUser,
                AuthorId = newUser.Id,
            };

            var result = await userManager.CreateAsync(newUser, userForRegisterDto.Password);

            if (result.Succeeded)
            {
                return(StatusCode(201)); // temporarly
                // return CreatedAtRoute();
            }
            return(BadRequest(result.Errors));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Register(UserForRegisterDto userForRegisterDto)
        {
            if (!RequestValidation.IsRequestValid <UserForRegisterDto>(userForRegisterDto))
            {
                return(BadRequest("Invalid request"));
            }

            var newUser = mapper.Map <User>(userForRegisterDto);

            var result = await userManager.CreateAsync(newUser, userForRegisterDto.Password);

            if (result.Succeeded)
            {
                var usr = await userManager.FindByNameAsync(newUser.UserName);

                //var res = await repo.InitializeUserAsyncReturnCode(Convert.ToString(usr.Id));

                try
                {
                    var res = await fsc.AccessControl.CreateUserAsync(Convert.ToString(usr.Id), false);

                    var r1 = await fsc.Directories.SetCustomMetadataAsync(res.RootDirectory, "Shared", false);

                    var r2 = await fsc.Directories.SetCustomMetadataAsync(res.RootDirectory, "ShareID", String.Empty);
                }
                catch (Exception)
                {
                    throw;
                }
                return(StatusCode(201));
            }

            return(BadRequest(result.Errors));
        }