Exemple #1
0
        public async Task <HttpResponseMessage> RegisterAdmin(RegisterAdminDTO adminDTO)
        {
            string userId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;

            logger.Info("UserId: " + userId + ": Requesting New Admin Insert");

            try
            {
                var result = await usersService.RegisterAdmin(adminDTO);

                if (result == null)
                {
                    logger.Info("Failed!");
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Failed!"));
                }

                logger.Info("Admin registered successfully!");
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (Exception e)
            {
                logger.Error(e);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
Exemple #2
0
        public async Task <IActionResult> CreateCarAdmin([FromBody] RegisterAdminDTO adminDTO)
        {
            if (ModelState.IsValid)
            {
                if (await AvioAdminService.AdminExists(adminDTO.Username))
                {
                    return(BadRequest("Admin already exists with that username!"));
                }

                if (await CarAdminService.AdminExists(adminDTO.Username))
                {
                    return(BadRequest("Admin already exists with that username!"));
                }

                if (adminDTO.Password != adminDTO.ConfirmPassword)
                {
                    return(BadRequest("Password and confirmation password don't match!"));
                }

                RegularUser user = new RegularUser()
                {
                    UserName = adminDTO.Username,
                    Status   = UserStatus.Activated
                };

                var foundAdmin = await UserManager.FindByNameAsync(user.UserName) != null;

                if (!foundAdmin)
                {
                    var createdAdmin = await UserManager.CreateAsync(user, adminDTO.Password);

                    if (createdAdmin.Succeeded)
                    {
                        await UserManager.AddToRoleAsync(user, "CarAdmin");

                        CarAdmin admin = new CarAdmin()
                        {
                            UserId       = user.Id,
                            CarCompanyId = (await RentACarService.GetCompanyByName(adminDTO.CompanyName)).CarCompanyId
                        };

                        if (admin.CarCompanyId > 0)
                        {
                            await CarAdminService.RegisterAdmin(user.Id, admin);

                            return(Ok(200));
                        }
                        else
                        {
                            return(BadRequest("Car company not found!"));
                        }
                    }
                }

                return(BadRequest("Admin already exists!"));
            }

            return(BadRequest("No sufficient data provided."));
        }
Exemple #3
0
        public async Task <object> RegisterAdmin(RegisterAdminDTO admin)
        {
            IdentityUser user = new IdentityUser
            {
                UserName = admin.userName,
                Email    = admin.email
            };

            return(await _userManager.CreateAsync(user, admin.password));
        }
Exemple #4
0
        public async Task <IdentityResult> RegisterAdmin(RegisterAdminDTO adminDTO)
        {
            ApplicationUser foundJmbg = GetByJmbg(adminDTO.Jmbg);

            if (foundJmbg != null)
            {
                throw new HttpException("A user with JMBG " + adminDTO.Jmbg + " is already in the system.");
            }

            ApplicationUser foundUserName = await FindUserByUserName(adminDTO.UserName);

            if (foundUserName != null)
            {
                throw new HttpException("Username " + adminDTO.UserName + " already exists.");
            }

            Admin user = new Admin
            {
                UserName  = adminDTO.UserName,
                FirstName = adminDTO.FirstName,
                LastName  = adminDTO.LastName,
                Email     = adminDTO.Email,
                Jmbg      = adminDTO.Jmbg,
                ShortName = adminDTO.ShortName
            };

            IdentityResult registeredAdmin = await db.AuthRepository.RegisterAdmin(user, adminDTO.Password);

            if (!registeredAdmin.Succeeded)
            {
                throw new HttpException("Failed to register the admin.");
            }

            emailsService.CreateRegistrationMailForAdminOrTeacher(user.Id);
            return(registeredAdmin);
        }
Exemple #5
0
 public ActionResult <object> Register([FromBody] RegisterAdminDTO register)
 {
     TryValidateModel(register);
     return(_authUtil.RegisterAdmin(register));
 }
 public Admin RegisterAdmin(RegisterAdminDTO registerAdminDTO)
 {
     return(_authService.RegisterAdmin(registerAdminDTO.Password));
 }