Skip to content

Commit

Permalink
Split previous joind.in URL into joind.in username and separate URL (#…
Browse files Browse the repository at this point in the history
…1174)

Remove double-declaration

Replace duplicate tests with joind.in URL tests
  • Loading branch information
chrisforrence authored and chartjes committed Oct 10, 2018
1 parent 0e54c18 commit e104a12
Show file tree
Hide file tree
Showing 13 changed files with 366 additions and 107 deletions.
27 changes: 14 additions & 13 deletions factories/Common.php
Expand Up @@ -12,19 +12,20 @@
*/
$factory->define(\OpenCFP\Domain\Model\User::class, function (\Faker\Generator $faker) {
return [
'email' => $faker->unique()->safeEmail,
'password' => \password_hash('secret', PASSWORD_BCRYPT),
'activated' => 1,
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'company' => $faker->company,
'twitter' => '@' . $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(),
'email' => $faker->unique()->safeEmail,
'password' => \password_hash('secret', PASSWORD_BCRYPT),
'activated' => 1,
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'company' => $faker->company,
'twitter' => '@' . $faker->userName,
'joindin_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(),
];
});

Expand Down
73 changes: 73 additions & 0 deletions migrations/20181002234013_create_user_joind_in_username_column.php
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2013-2018 OpenCFP
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/opencfp/opencfp
*/
use Cartalyst\Sentinel\Users\EloquentUser;
use Phinx\Migration\AbstractMigration;

class CreateUserJoindInUsernameColumn extends AbstractMigration
{
/** @var Capsule $capsule */
public $capsule;

public function bootEloquent(): void
{
$adapter = $this->getAdapter()->getAdapter();
$options = $adapter->getOptions();
$this->capsule = new Capsule();
$this->capsule->addConnection([
'driver' => 'mysql',
'database' => $options['name'],
]);
$this->capsule->getConnection()->setPdo($adapter->getConnection());
$this->capsule->bootEloquent();
$this->capsule->setAsGlobal();
}

public function up(): void
{
// Create joindin_username
$this->table('users')
->addColumn('joindin_username', 'string', ['null' => true])
->update();

// Go through each record in user, strip out (https://joind.in/user/) and copy to joindin_username
$joindInRegex = '/^https:\/\/joind\.in\/user\/(.{1,100})$/';

$users = EloquentUser::all();

foreach ($users as $user) {
if (\preg_match($joindInRegex, $user->url, $matches) === 1) {
$user->joindin_username = $matches[1];
$user->url = null;
$user->save();
}
}
}

public function down(): void
{
// Go through each record in user, update `url` to move the joindin_username to there
$users = EloquentUser::all();

foreach ($users as $user) {
$user->url = $user->joindin_username
? 'https://joind.in/user/' . $user->joindin_username
: null;
$user->joindin_username = null;
$user->save();
}
// Drop the joindin_username column
$this->table('users')
->removeColumn('joindin_username')
->update();
}
}
9 changes: 9 additions & 0 deletions resources/views/admin/speaker/view.twig
Expand Up @@ -15,6 +15,15 @@
<div>
{% if speaker.company %}<span class="mr-3"><i class="fa fa-building"></i> {{ speaker.company }}</span>{% endif %}
{% if speaker.twitter %}<span class="mr-3"><a class="hover:text-brand" target="_blank" href="{{ speaker.twitterUrl }}" rel="noopener noreferrer"><i class="fa fa-twitter"></i> @{{ speaker.twitter }}</a></span>{% endif %}
{% if speaker.joindInUsername %}
<span class="mr-3">
<a class="hover:text-brand" target="_blank"
href="{{ speaker.joindInUrl }}"
rel="noopener noreferrer">
<i class="fa fa-commenting-o"></i> {{ speaker.joindInUsername }}
</a>
</span>
{% endif %}
{% if speaker.email %}<span class="mr-3"><i class="fa fa-envelope"></i> {{ speaker.email }}</span>{% endif %}
</div>
</div>
Expand Down
17 changes: 14 additions & 3 deletions resources/views/dashboard.twig
Expand Up @@ -11,7 +11,7 @@ function deleteTalk(tid) {
if (data.delete == 'ok') {
$("#talk-"+tid).remove();
} else if (data.delete == 'no-user') {
alert("You must be logged in to delete talks")
alert("You must be logged in to delete talks");
} else {
alert("Unable to delete talk");
}
Expand Down Expand Up @@ -47,11 +47,22 @@ function deleteTalk(tid) {
{% if profile.company %}
<p>{{ profile.company }}</p>
{% endif %}

{% if profile.twitter %}
<a class="text-white text-xs" href="https://twitter.com/{{ profile.twitter }}" title="{{ profile.name }} on Twitter"><i class="fa fa-twitter"></i> @{{ profile.twitter }}</a>
<a class="text-white text-xs" href="https://twitter.com/{{ profile.twitter }}" title="{{ profile.name }} on Twitter"><i class="fa fa-fw fa-twitter"></i> @{{ profile.twitter }}</a>
{% endif %}

{% if profile.joindInUsername %}
<br /><a class="text-white text-xs"
href="{{ profile.joindInUrl }}"
title="Follow {{ profile.name }} on joind.in">
<i class="fa fa-fw fa-commenting-o"></i> {{ profile.joindInUsername }}
</a>
{% endif %}

{% if profile.url %}
| <a class="text-white text-xs" href="{{ profile.url }}">{{ profile.url }}</a>
<br /><a class="text-white text-xs" href="{{ profile.url }}">
<i class="fa fa-fw fa-desktop"></i> {{ profile.url }}</a>
{% endif %}
</div>
</div>
Expand Down
9 changes: 6 additions & 3 deletions resources/views/forms/_user.twig
Expand Up @@ -20,10 +20,13 @@
<label for="form-user-twitter">Twitter</label>
<input id="form-user-twitter" type="text" name="twitter" placeholder="@twitter" value="{{ twitter | default('') }}">

<label for="form-user-url">joind.in</label>
<input id="form-user-url" type="text" name="url" placeholder="https://joind.in/user/" value="{{ url | default('') }}">
<label for="form-user-joindin-username">joind.in username</label>
<input id="form-user-joindin-username" type="text" name="joindin_username" placeholder="first_lastname" value="{{ joindin_username | default('') }}">

{% if site.online_conference == false %}
<label for="form-user-url">URL</label>
<input id="form-user-url" type="text" name="url" placeholder="https://example.com" value="{{ url | default('') }}">

{% if site.online_conference == false %}
<h3 class="text-base text-dark-soft mt-4">Travel Assistance</h3>
<div>
<input id="form-transportation" name="transportation" type="checkbox" value="1" {% if transportation == '1' %}checked{% endif %}>
Expand Down
30 changes: 30 additions & 0 deletions src/Domain/Speaker/SpeakerProfile.php
Expand Up @@ -140,6 +140,36 @@ public function getTwitterUrl(): string
return 'https:://twitter.com/' . $twitter;
}

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

return $this->speaker->joindin_username;
}

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

$username = $this->speaker->joindin_username;

if ($username === null || \trim($username) === '') {
return '';
}

return 'https://joind.in/user/' . $username;
}

/**
* @throws NotAllowedException
*
Expand Down
33 changes: 17 additions & 16 deletions src/Http/Action/Profile/EditAction.php
Expand Up @@ -73,22 +73,23 @@ public function __invoke(HttpFoundation\Request $request): HttpFoundation\Respon
$speakerData = Model\User::find($user->getId())->toArray();

$content = $this->twig->render('user/edit.twig', [
'email' => $user->getLogin(),
'first_name' => $speakerData['first_name'],
'last_name' => $speakerData['last_name'],
'company' => $speakerData['company'],
'twitter' => $speakerData['twitter'],
'url' => $speakerData['url'],
'speaker_info' => $speakerData['info'],
'speaker_bio' => $speakerData['bio'],
'speaker_photo' => $speakerData['photo_path'],
'preview_photo' => $this->path->uploadPath() . $speakerData['photo_path'],
'airport' => $speakerData['airport'],
'transportation' => $speakerData['transportation'],
'hotel' => $speakerData['hotel'],
'id' => $user->getId(),
'formAction' => $this->urlGenerator->generate('user_update'),
'buttonInfo' => 'Update Profile',
'email' => $user->getLogin(),
'first_name' => $speakerData['first_name'],
'last_name' => $speakerData['last_name'],
'company' => $speakerData['company'],
'twitter' => $speakerData['twitter'],
'joindin_username' => $speakerData['joindin_username'],
'url' => $speakerData['url'],
'speaker_info' => $speakerData['info'],
'speaker_bio' => $speakerData['bio'],
'speaker_photo' => $speakerData['photo_path'],
'preview_photo' => $this->path->uploadPath() . $speakerData['photo_path'],
'airport' => $speakerData['airport'],
'transportation' => $speakerData['transportation'],
'hotel' => $speakerData['hotel'],
'id' => $user->getId(),
'formAction' => $this->urlGenerator->generate('user_update'),
'buttonInfo' => 'Update Profile',
]);

return new HttpFoundation\Response($content);
Expand Down
25 changes: 13 additions & 12 deletions src/Http/Action/Profile/ProcessAction.php
Expand Up @@ -126,18 +126,19 @@ public function __invoke(HttpFoundation\Request $request): HttpFoundation\Respon
private function getFormData(HttpFoundation\Request $request): array
{
return [
'email' => $request->get('email'),
'user_id' => $request->get('id'),
'first_name' => $request->get('first_name'),
'last_name' => $request->get('last_name'),
'company' => $request->get('company'),
'twitter' => $request->get('twitter'),
'url' => $request->get('url'),
'airport' => $request->get('airport'),
'transportation' => (int) $request->get('transportation'),
'hotel' => (int) $request->get('hotel'),
'speaker_info' => $request->get('speaker_info') ?: null,
'speaker_bio' => $request->get('speaker_bio') ?: null,
'email' => $request->get('email'),
'user_id' => $request->get('id'),
'first_name' => $request->get('first_name'),
'last_name' => $request->get('last_name'),
'company' => $request->get('company'),
'twitter' => $request->get('twitter'),
'joindin_username' => $request->get('joindin_username'),
'url' => $request->get('url'),
'airport' => $request->get('airport'),
'transportation' => (int) $request->get('transportation'),
'hotel' => (int) $request->get('hotel'),
'speaker_info' => $request->get('speaker_info') ?: null,
'speaker_bio' => $request->get('speaker_bio') ?: null,
];
}

Expand Down
21 changes: 18 additions & 3 deletions src/Http/Form/SignupForm.php
Expand Up @@ -34,6 +34,7 @@ class SignupForm extends Form
'hotel',
'speaker_photo',
'agree_coc',
'joindin_username',
'url',
];

Expand Down Expand Up @@ -61,7 +62,7 @@ public function validateAll(string $action = 'create'): bool
$validSpeakerBio = $this->validateSpeakerBio();
}

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

public function validateSpeakerPhoto(): bool
Expand Down Expand Up @@ -201,15 +202,29 @@ public function validateLastName(): bool
return $validationResponse;
}

public function validateJoindInUsername(): bool
{
if (!isset($this->cleanData['joindin_username'])
|| $this->cleanData['joindin_username'] == ''
|| \preg_match('/^[a-zA-Z0-9\-_\.]{1,100}$/', $this->cleanData['joindin_username'])
) {
return true;
}

$this->addErrorMessage('Please enter a valid joind.in username.');

return false;
}

public function validateUrl(): bool
{
if (\preg_match('/^https:\/\/joind\.in\/user\/[a-zA-Z0-9\-_\.]{1,100}$/', $this->cleanData['url'])
if (\filter_var($this->cleanData['url'], FILTER_VALIDATE_URL) !== false
|| !isset($this->cleanData['url'])
|| $this->cleanData['url'] == ''
) {
return true;
}
$this->addErrorMessage('You did not enter a valid joind.in URL');
$this->addErrorMessage('Please enter a valid URL.');

return false;
}
Expand Down

0 comments on commit e104a12

Please sign in to comment.