/**
  * Retrieve user and ensure user is exist
  * 
  * @param  mixed $id
  * @return AccountDomainModels\User
  */
 protected function retrieveUser($id)
 {
     $user = $this->userRepository->findById($id);
     if (is_null($user)) {
         throw new ValueNotFoundException("[{$id}] is not valid user id");
     }
     return $user;
 }
Example #2
0
 /**
  * Determine if specification was satisfied by given candidate
  * 
  * @param  SpecificationCandidate $candidate
  * @return boolean
  */
 public function isSatisfiedBy(SpecificationCandidate $candidate)
 {
     if ($user = $this->userRepository->findByUsername($candidate->value())) {
         if (!$user->id()->equal($this->id)) {
             return false;
         }
     }
     return true;
 }
 /**
  * Handle new user registration
  * 
  * @param  RegisterNewUser $command
  * @return void
  */
 public function handle(RegisterNewUser $command)
 {
     $username = new AccountDomainModels\Username($command->username);
     $email = new FoundationDomainModels\Email($command->email);
     $description = new FoundationDomainModels\Description($command->description);
     $id = $this->userRepository->nextIdentity();
     $roles = count($command->roles) ? $this->buildRoles($command->roles) : $this->roleRepository->getDefaultRoles();
     $this->ensureUsernameIsUnique($username);
     $this->ensureEmailIsUnique($email);
     $user = new AccountDomainModels\User($id, $username, $email, $description, $roles);
     $this->userRepository->save($user);
     $this->events->fire([new UserWasRegistered($user)]);
 }
Example #4
0
 public function putUpdateAvatar(Dispatcher $bus, Request $request, UserRepository $userRepository, LibraryRepository $libraryRepository, $id)
 {
     $userId = $this->authis->check('account.admin.users.update.get') ? $id : $request->user()->id;
     $library = $libraryRepository->findByPath($request->avatar);
     $user = $userRepository->findById($userId)->toArray();
     $description = $user['description'];
     $this->validate($request, ['avatar' => 'required']);
     $description['avatar'] = $request->avatar;
     $bus->dispatch(new DescribeUser($userId, $user['username'], $user['email'], $description));
     if ($library) {
         $library = $library->toArray();
         $libraryDescription = $library['description'];
         $libraryDescription['visibility'] = 'public';
         $bus->dispatch(new DescribeLibrary($library['id'], $libraryDescription));
     }
     return $this->formSuccess(route('account.admin.profile.index.get'), ['message' => trans('inoplate-account::messages.profile.avatar_updated')]);
 }
Example #5
0
 public function store(Request $request, Bus $bus, UserRepository $userRepository)
 {
     $this->validate($request, ['reg_no' => 'required|max:255|unique:lecturers', 'local_reg_no' => 'required|max:255|unique:lecturers', 'name' => 'required|max:255', 'id_number' => 'unique:lecturers', 'country_id' => 'exists:countries,id']);
     $lecturer = new Lecturer();
     $lecturer->reg_no = $request->reg_no;
     $lecturer->local_reg_no = $request->local_reg_no;
     $lecturer->name = $request->name;
     $lecturer->status = $request->status;
     $lecturer->id_number = $request->id_number;
     $lecturer->mother_maiden_name = $request->mother_maiden_name;
     $lecturer->country_id = $request->country_id;
     $lecturer->avatar = $request->avatar;
     $user = $userRepository->findByUsername($request->reg_no);
     if (!$user) {
         $role = Role::where('name', 'Lecturer')->first();
         $roles = $role ? [$role->id] : [];
         $desc = ['password' => bcrypt($request->reg_no), 'name' => $request->name, 'active' => true];
         $bus->dispatch(new RegisterNewUser($request->reg_no, $request->reg_no . '@email.com', $roles, $desc));
         $user = $userRepository->findByUsername($request->reg_no);
     }
     $lecturer->user_id = $user->id()->value();
     $lecturer->save();
     return $this->formSuccess(route('admin.employee.lecturer.index', ['id' => $lecturer->id]), ['message' => 'Dosen berhasil disimpan', 'lecturer' => $lecturer]);
 }
Example #6
0
 public function store(Request $request, Bus $bus, UserRepository $userRepository)
 {
     $this->validate($request, ['reg_no' => 'required|max:255|unique:students', 'name' => 'required|max:255', 'entry_year' => 'required', 'program_id' => 'required|exists:programs,id', 'id_number' => 'unique:students', 'country_id' => 'exists:countries,id']);
     $student = new Student();
     $student->reg_no = $request->reg_no;
     $student->name = $request->name;
     $student->entry_year = $request->entry_year;
     $student->program_id = $request->program_id;
     $student->id_number = $request->id_number;
     $student->mother_maiden_name = $request->mother_maiden_name;
     $student->country_id = $request->country_id;
     $student->avatar = $request->avatar;
     $user = $userRepository->findByUsername($request->reg_no);
     if (!$user) {
         $role = Role::where('name', 'Student')->first();
         $roles = $role ? [$role->id] : [];
         $desc = ['password' => bcrypt($request->reg_no), 'name' => $request->name, 'active' => true];
         $bus->dispatch(new RegisterNewUser($request->reg_no, $request->reg_no . '@email.com', $roles, $desc));
         $user = $userRepository->findByUsername($request->reg_no);
     }
     $student->user_id = $user->id()->value();
     $student->save();
     return $this->formSuccess(route('admin.student.student.index', ['id' => $student->id]), ['message' => 'Mahasiswa berhasil disimpan', 'student' => $student]);
 }