Esempio n. 1
0
 public function actionAutomatic($hash, Application $app)
 {
     // Find project from hash
     $project = Project::where('hash', '=', $hash)->first();
     // Check that project exists
     if (is_null($project)) {
         $app->abort(404, 'Project not found');
     }
     // Check that project is set to be automatically triggered to deploy
     if (!$project->isTriggeredAutomatically()) {
         $app->abort(404, 'Project not set to allow automatic deployment');
     }
     // Create host object
     $projectHostClass = 'Deployer\\Host\\' . $project->host;
     $host = new $projectHostClass($app['request']);
     // Check pushed branch is the branch that the project deploys from
     $branch = $host->getBranch();
     if ($project->branch != $branch) {
         $app->abort(404, 'Pushed branch is not set to trigger deployment');
     }
     // Check the pusher is a user
     $pusher = $host->getPusher();
     $username = Username::where('host', '=', $project->host)->where('username', '=', $pusher)->first();
     if (is_null($username)) {
         $app->abort(404, 'Unknown pusher');
     }
     $user = $username->user;
     // OK, all looks good, let's attempt a deployment
     $deployment = new Deployment();
     $deployment->isBeingTriggeredAutomatically();
     if (!$deployment->process($project, $user, $app)) {
         $app->abort(500, 'Deployment failed');
     }
     return 'Deployment successful';
 }
Esempio n. 2
0
 public function actionProcessEdit(User $user, Application $app)
 {
     $input = $app['request']->request->all();
     $errors = array();
     $validation = $app['validator']($input, User::$rules, User::$messages);
     if ($validation->passes()) {
         try {
             $user->first_name = $input['first_name'];
             $user->last_name = $input['last_name'];
             $user->email = $input['email'];
             if (!empty($input['password'])) {
                 $user->password = $input['password'];
             }
             $user->save();
             foreach ($input['hosts'] as $hostName => $usernameValue) {
                 $username = $user->usernames()->where('host', '=', $hostName)->first();
                 if (!empty($usernameValue)) {
                     if (is_null($username)) {
                         $username = new Username();
                         $username->host = $hostName;
                     }
                     $username->username = $usernameValue;
                     $username->user()->associate($user);
                     $username->save();
                 } elseif (!is_null($username)) {
                     $username->delete();
                 }
             }
             return $app->redirect('user.list', array('successMessage' => 'User successfully edited'));
         } catch (Cartalyst\Sentry\Users\UserExistsException $e) {
             $errors[] = 'A user with that email address already exists';
         } catch (Illuminate\Database\QueryException $e) {
             $errors[] = 'Unable to update host accounts';
         }
     }
     return $app->forward(array('user.edit', array('user' => $user->id)), array('errorMessages' => $validation->messages()->all() + $errors, 'oldInput' => $app['request']->request->all()));
 }