Example #1
0
        public async Task <IActionResult> SignUp(AppUserAddDto appUserAddDto, [FromServices] IAppUserRoleService appUserRoleService, [FromServices] IAppRoleService appRoleService)
        {
            appUserAddDto.Email    = appUserAddDto.Email.ToLower();
            appUserAddDto.UserName = appUserAddDto.UserName.ToLower();
            var appUser = await _appUserService.FindByEmail(appUserAddDto.Email);

            if (appUser != null)
            {
                return(BadRequest(new { Error = $"{appUserAddDto.Email} alınmıştır. Farklı bir e-posta dene", ErrorType = "EMAIL_IS_ALREADY_IN_USE" }));
            }

            appUserAddDto.Password  = BCrypt.Net.BCrypt.HashPassword(appUserAddDto.Password);
            appUserAddDto.ImagePath = "default.jpg";

            await _appUserService.AddAsync(_mapper.Map <AppUser>(appUserAddDto));

            var user = await _appUserService.FindByEmail(appUserAddDto.Email);

            var role = await appRoleService.FindByNameAsync(RoleInfo.Member);

            await appUserRoleService.AddAsync(new AppUserRole
            {
                AppRoleId = role.Id,
                AppUserId = user.Id
            });

            var newUser = await _appUserService.FindByEmail(appUserAddDto.Email);

            var roles = await _appUserService.GetRolesByEmail(appUserAddDto.Email);

            var token = _jwtService.GenerateJwt(newUser, roles);

            return(Created("", new { token.Token, newUser.Id, expiresIn = 30 * 60 }));
        }
Example #2
0
        public async Task <IActionResult> SignUp(AppUserAddDto appUserAddDto,
                                                 [FromServices] IAppUserRoleService appUserRoleService,
                                                 [FromServices] IAppRoleService appRoleService)
        {
            var appUser = await _appUserService.FindByUserName
                              (appUserAddDto.UserName);

            if (appUser == null)
            {
                return(BadRequest($"{appUserAddDto.UserName} already taken"));
            }

            await _appUserService.AddAsync(_mapper.Map <AppUser>(appUserAddDto));

            var user = await _appUserService.FindByUserName(appUserAddDto.UserName);

            var role = await appRoleService.FindByName(RoleInfo.Member);

            await appUserRoleService.AddAsync(new AppUserRole
            {
                AppRoleId = role.Id,
                AppUserId = user.Id
            });

            return(Created("", appUserAddDto));
        }
Example #3
0
        public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByNameAsync(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.AddAsync(new Entities.Concrete.AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            var memberRole = await appRoleService.FindByNameAsync(RoleInfo.Member);

            if (memberRole == null)
            {
                await appRoleService.AddAsync(new Entities.Concrete.AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByEmail("*****@*****.**");

            if (adminUser == null)
            {
                string password = BCrypt.Net.BCrypt.HashPassword("1");

                await appUserService.AddAsync(new Entities.Concrete.AppUser
                {
                    Name      = "Admin Test",
                    Password  = password,
                    Email     = "*****@*****.**",
                    ImagePath = "default.jpg",
                    UserName  = "******",
                    Surname   = "Admin Surname",
                });


                var role = await appRoleService.FindByNameAsync(RoleInfo.Admin);

                var admin = await appUserService.FindByEmail("*****@*****.**");

                await appUserRoleService.AddAsync(new Entities.Concrete.AppUserRole
                {
                    AppUserId = admin.Id,
                    AppRoleId = role.Id
                });
            }
        }
        public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByNameAsync(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.AddAsync(new AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            var memberRole = await appRoleService.FindByNameAsync(RoleInfo.Member);

            if (memberRole == null)
            {
                await appRoleService.AddAsync(new AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByUserNameAsync("emre");

            if (adminUser == null)
            {
                await appUserService.AddAsync(new AppUser
                {
                    FullName = "emre yüksek",
                    UserName = "******",
                    Password = "******"
                });

                var role = await appRoleService.FindByNameAsync(RoleInfo.Admin);

                var admin = await appUserService.FindByUserNameAsync("emre");

                await appUserRoleService.AddAsync(new AppUserRole
                {
                    AppUserId = admin.Id,
                    AppRoleId = role.Id
                });
            }
        }
Example #5
0
        public static async Task Seed(IAppUserService appUserService,
                                      IAppUserRoleService appUserRoleService, IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByName(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.AddAsync(new Entities.Concrete.AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            var memberRole = await appRoleService.FindByName(RoleInfo.Member);

            if (adminRole == null)
            {
                await appRoleService.AddAsync(new Entities.Concrete.AppRole
                {
                    Name = RoleInfo.Member
                });
            }
            var adminUser = await appUserService.FindByUserName("Uzay");

            if (adminUser == null)
            {
                await appUserService.AddAsync(new AppUser
                {
                    FullName = "Uzay KAHRAMAN",
                    UserName = "******",
                    Password = "******"
                });

                var role = await appRoleService.FindByName(RoleInfo.Admin);

                var admin = await appUserService.FindByUserName("Uzay");

                await appUserRoleService.AddAsync(new AppUserRole
                {
                    AppUserId = admin.Id,
                    AppRoleId = role.Id
                });
            }
        }