Skip to content

Commit

Permalink
Speaker Profile: Add wporg username & speaker experience fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Mar 16, 2020
1 parent 1841319 commit e32074f
Show file tree
Hide file tree
Showing 11 changed files with 1,783 additions and 4 deletions.
2 changes: 2 additions & 0 deletions factories/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
'company' => $faker->company,
'twitter' => '@' . $faker->userName,
'joindin_username' => $faker->userName,
'wporg_username' => $faker->userName,
'activated_at' => $faker->dateTimeInInterval('-2 months', '-1 months'),
'last_login' => $faker->dateTimeInInterval('-5 days', 'now'),
'transportation' => $faker->randomElement([0, 1]),
'hotel' => $faker->randomElement([0, 1]),
'info' => $faker->realText(),
'bio' => $faker->realText(),
'exp' => $faker->realText(),
];
});

Expand Down
34 changes: 34 additions & 0 deletions migrations/Version20200312193057.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace OpenCFP\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use phpDocumentor\Reflection\Type;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20200312193057 extends AbstractMigration
{
public function getDescription() : string
{
return 'Add wporg username & speaker experience.';
}

public function up(Schema $schema) : void
{
$table = $schema->getTable('users');
$table->addColumn('wporg', 'string', ['notnull' => false]);
$table->addColumn('exp', 'text', ['notnull' => false]);
}

public function down(Schema $schema) : void
{
$table = $schema->getTable('users');
$table->removeColumn('wporg');
$table->removeColumn('exp');
}
}
2 changes: 1 addition & 1 deletion resources/assets/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/

// Vendor
$fa-font-path: "/assets/fonts";
$fa-font-path: "//netdna.bootstrapcdn.com/font-awesome/4.7.0/fonts";
@import "~font-awesome/scss/font-awesome.scss";

// Font Imports
Expand Down
5 changes: 5 additions & 0 deletions resources/views/dashboard.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ function deleteTalk(tid) {
{% endif %}

<div class="account-banner__links">
{% if profile.wporg %}
<a class="text-xs" href="https://profiles.wordpress.org/{{ profile.wporg }}">
<i class="fa fa-fw fa-wordpress" aria-hidden></i> {{ profile.wporg }}
</a><br />
{% endif %}
{% if profile.twitter %}
<a class="text-xs" href="https://twitter.com/{{ profile.twitter }}">
<i class="fa fa-fw fa-twitter" aria-hidden></i> @{{ profile.twitter }}
Expand Down
6 changes: 6 additions & 0 deletions resources/views/forms/_user.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<label for="form-user-company">Company</label>
<input id="form-user-company" type="text" name="company" placeholder="Company" value="{{ company | default('') }}">

<label for="form-user-wporg">WordPress.org username</label>
<input id="form-user-wporg" type="text" name="wporg" placeholder="@profile" value="{{ wporg | default('') }}">

<label for="form-user-twitter">Twitter</label>
<input id="form-user-twitter" type="text" name="twitter" placeholder="@twitter" value="{{ twitter | default('') }}">

Expand All @@ -29,6 +32,9 @@
<label for="form-user-notes">Additional Notes</label>
<textarea id="form-user-notes" name="speaker_info" placeholder="" rows="5" aria-describedby="form-user-notes-help">{{ speaker_info | default('') }}</textarea>

<label for="form-user-exp">Speaking Experience</label>
<p id="form-user-exp-help" class="form-help">Please share with us your past speaking experience - including any meetups, WordCamps, or other conferences. If this is your first time speaking, that is ok too!</p>
<textarea id="form-user-exp" name="speaker_exp" placeholder="" rows="5" aria-describedby="form-user-exp-help">{{ speaker_exp | default('') }}</textarea>

<p><strong>Avatar</strong></p>
<div class="flex form-user-avatar">
Expand Down
5 changes: 5 additions & 0 deletions src/Domain/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public function throttle(): HasMany
return $this->hasMany(Throttle::class);
}

public static function wporgUrl(?string $handle): string
{
return !$handle || !\trim($handle) ? '' : ('https://profiles.wordpress.org/' . $handle);
}

public static function twitterUrl(?string $handle): string
{
return !$handle || !\trim($handle) ? '' : ('https://twitter.com/' . $handle);
Expand Down
36 changes: 36 additions & 0 deletions src/Domain/Speaker/SpeakerProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ public function getCompany()
return $this->speaker->company;
}

/**
* @throws NotAllowedException
*
* @return null|string
*/
public function getWPorg()
{
$this->assertAllowedToSee('wporg');

return $this->speaker->wporg;
}

/**
* @throws NotAllowedException
*
* @return string
*/
public function getWPorgUrl(): string
{
$this->assertAllowedToSee('wporg');

return User::wporgUrl($this->speaker->wporg);
}

/**
* @throws NotAllowedException
*
Expand Down Expand Up @@ -200,6 +224,18 @@ public function getBio()
return $this->speaker->bio;
}

/**
* @throws NotAllowedException
*
* @return null|string
*/
public function getExp()
{
$this->assertAllowedToSee('exp');

return $this->speaker->exp;
}

/**
* @throws NotAllowedException
*
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Action/Profile/EditAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ public function __invoke(HttpFoundation\Request $request): HttpFoundation\Respon
'first_name' => $speakerData['first_name'],
'last_name' => $speakerData['last_name'],
'company' => $speakerData['company'],
'wporg' => $speakerData['wporg'],
'twitter' => $speakerData['twitter'],
'joindin_username' => $speakerData['joindin_username'],
'url' => $speakerData['url'],
'speaker_info' => $speakerData['info'],
'speaker_bio' => $speakerData['bio'],
'speaker_exp' => $speakerData['exp'],
'speaker_photo' => $speakerData['photo_path'],
'preview_photo' => $this->path->uploadPath() . $speakerData['photo_path'],
'airport' => $speakerData['airport'],
Expand Down
10 changes: 10 additions & 0 deletions src/Http/Action/Profile/ProcessAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private function getFormData(HttpFoundation\Request $request): array
'first_name' => $request->request->get('first_name'),
'last_name' => $request->request->get('last_name'),
'company' => $request->request->get('company'),
'wporg' => $request->request->get('wporg'),
'twitter' => $request->request->get('twitter'),
'joindin_username' => $request->request->get('joindin_username'),
'url' => $request->request->get('url'),
Expand All @@ -139,6 +140,7 @@ private function getFormData(HttpFoundation\Request $request): array
'hotel' => $request->request->getInt('hotel'),
'speaker_info' => $request->request->get('speaker_info') ?: null,
'speaker_bio' => $request->request->get('speaker_bio') ?: null,
'speaker_exp' => $request->request->get('speaker_exp') ?: null,
];
}

Expand All @@ -151,19 +153,27 @@ private function getFormData(HttpFoundation\Request $request): array
*/
private function transformSanitizedData(array $sanitizedData): array
{
$sanitizedData['wporg'] = \preg_replace(
'/^@/',
'',
$sanitizedData['wporg']
);

$sanitizedData['twitter'] = \preg_replace(
'/^@/',
'',
$sanitizedData['twitter']
);

$sanitizedData['bio'] = $sanitizedData['speaker_bio'];
$sanitizedData['exp'] = $sanitizedData['speaker_exp'];
$sanitizedData['info'] = $sanitizedData['speaker_info'];
$sanitizedData['id'] = $sanitizedData['user_id'];
$sanitizedData['has_made_profile'] = 1;

unset(
$sanitizedData['speaker_bio'],
$sanitizedData['speaker_exp'],
$sanitizedData['speaker_info'],
$sanitizedData['user_id']
);
Expand Down
35 changes: 35 additions & 0 deletions src/Http/Form/SignupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ class SignupForm extends Form
'first_name',
'last_name',
'company',
'wporg',
'twitter',
'speaker_info',
'speaker_bio',
'speaker_exp',
'transportation',
'hotel',
'speaker_photo',
Expand Down Expand Up @@ -64,6 +66,12 @@ public function validateAll(string $action = 'create'): bool
$validSpeakerBio = $this->validateSpeakerBio();
}

$validSpeakerExp = true;

if (!empty($this->taintedData['speaker_exp'])) {
$validSpeakerExp = $this->validateSpeakerExp();
}

return $this->validateEmail() && $validPasswords && $this->validateFirstName() && $this->validateLastName() && $this->validateUrl() && $validSpeakerInfo && $validSpeakerBio && $this->validateSpeakerPhoto() && $agreeCoc && $this->validateJoindInUsername() && $this->validateTransportationRequests();
}

Expand Down Expand Up @@ -282,6 +290,24 @@ public function validateSpeakerBio(): bool
return $validationResponse;
}

public function validateSpeakerExp(): bool
{
$speakerExp = \filter_var(
$this->cleanData['speaker_exp'],
FILTER_SANITIZE_STRING
);
$validationResponse = true;
$speakerExp = \strip_tags($speakerExp);
$speakerExp = $this->purifier->purify($speakerExp);

if (empty($speakerExp)) {
$this->addErrorMessage('You submitted speaker experience information but it was empty after sanitizing');
$validationResponse = false;
}

return $validationResponse;
}

public function sanitize()
{
parent::sanitize();
Expand All @@ -295,6 +321,15 @@ public function sanitize()
$this->cleanData['password2'] = $this->taintedData['password2'];
}

// Remove leading @ for wporg profile name
if (isset($this->taintedData['wporg'])) {
$this->cleanData['wporg'] = \preg_replace(
'/^@/',
'',
$this->taintedData['wporg']
);
}

// Remove leading @ for twitter
if (isset($this->taintedData['twitter'])) {
$this->cleanData['twitter'] = \preg_replace(
Expand Down
Loading

0 comments on commit e32074f

Please sign in to comment.