Ejemplo n.º 1
0
 /**
  * Add user in database
  * @return string
  * @throws NativeException
  */
 public function actionAdduser()
 {
     echo "Login:"******"Email:";
     $email = Console::$Input->read();
     if (!Str::isEmail($email)) {
         throw new NativeException('Email is bad');
     }
     echo "Password:"******"RoleId (1 = onlyread, 2 = user, 3 = moderator, 4 = admin):";
     $role = (int) Console::$Input->read();
     if (!Arr::in($role, [1, 2, 3, 4])) {
         $role = 2;
     }
     if (User::isMailExist($email) || User::isLoginExist($login)) {
         throw new NativeException('User with this email or login is always exist');
     }
     $salt = Console::$Properties->get('passwordSalt');
     $user = new User();
     $user->login = $login;
     $user->email = $email;
     $user->password = Security::password_hash($pass, $salt);
     $user->role_id = $role;
     $user->save();
     $profile = new Profile();
     $profile->user_id = $user->id;
     $profile->save();
     return 'User was successful added to database!';
 }
Ejemplo n.º 2
0
 /**
  * Run applications and display output
  * @throws \DebugBar\DebugBarException
  */
 public function run()
 {
     $html = null;
     // lets try to get html full content to page render
     try {
         /** @var \Ffcms\Core\Arch\Controller $callClass */
         $callClass = null;
         $callMethod = 'action' . self::$Request->getAction();
         // founded callback injection alias
         if (self::$Request->getCallbackAlias() !== false) {
             $cName = self::$Request->getCallbackAlias();
             if (class_exists($cName)) {
                 $callClass = new $cName();
             } else {
                 throw new NotFoundException('Callback alias of class "' . App::$Security->strip_tags($cName) . '" is not founded');
             }
         } else {
             // typical parsing of native apps
             $cName = '\\Apps\\Controller\\' . env_name . '\\' . self::$Request->getController();
             // try to initialize class object
             if (class_exists($cName)) {
                 $callClass = new $cName();
             } else {
                 throw new NotFoundException('Application can not be runned. Initialized class not founded: ' . App::$Security->strip_tags($cName));
             }
         }
         // try to call method of founded callback class
         if (method_exists($callClass, $callMethod)) {
             $actionQuery = [];
             // prepare action params for callback
             if (!Str::likeEmpty(self::$Request->getID())) {
                 $actionQuery[] = self::$Request->getID();
                 if (!Str::likeEmpty(self::$Request->getAdd())) {
                     $actionQuery[] = self::$Request->getAdd();
                 }
             }
             // get controller method arguments count
             $reflection = new \ReflectionMethod($callClass, $callMethod);
             $argumentCount = 0;
             foreach ($reflection->getParameters() as $arg) {
                 if (!$arg->isOptional()) {
                     $argumentCount++;
                 }
             }
             // check method arguments count and current request count to prevent warnings
             if (count($actionQuery) < $argumentCount) {
                 throw new NotFoundException(__('Arguments for method %method% is not enough. Expected: %required%, got: %current%.', ['method' => $callMethod, 'required' => $argumentCount, 'current' => count($actionQuery)]));
             }
             // make callback call to action in controller and get response
             $actionResponse = call_user_func_array([$callClass, $callMethod], $actionQuery);
             if ($actionResponse !== null && !Str::likeEmpty($actionResponse)) {
                 // set response to controller property object
                 $callClass->setOutput($actionResponse);
             }
             // build full compiled output html data
             $html = $callClass->buildOutput();
         } else {
             throw new NotFoundException('Method "' . App::$Security->strip_tags($callMethod) . '()" not founded in "' . get_class($callClass) . '"');
         }
     } catch (NotFoundException $e) {
         // catch exceptions and set output
         $html = $e->display();
     } catch (ForbiddenException $e) {
         $html = $e->display();
     } catch (SyntaxException $e) {
         $html = $e->display();
     } catch (JsonException $e) {
         $html = $e->display();
     } catch (NativeException $e) {
         $html = $e->display();
     } catch (\Exception $e) {
         // catch all other exceptions
         $html = (new NativeException($e->getMessage()))->display();
     }
     // set full rendered content to response builder
     self::$Response->setContent($html);
     // echo full response to user via http foundation
     self::$Response->send();
 }