Skip to content

Commit 92bd9c0

Browse files
committed
[spalenque] - #13525 * add github username field to profile form
1 parent 031af66 commit 92bd9c0

4 files changed

Lines changed: 42 additions & 1 deletion

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2017 OpenStack Foundation
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
**/
15+
16+
class GitHubUserField extends TextField
17+
{
18+
public function validate($validator) {
19+
20+
$service = new RestfulService('https://api.github.com');
21+
$response = $service->request('/users/'.$this->value);
22+
23+
$status_code = $response->getStatusCode();
24+
$user_data = json_decode($response->getBody());
25+
26+
if($status_code == 200 && $user_data->id) {
27+
return true;
28+
} else {
29+
$validator->validationError(
30+
$this->name, "Please enter a valid GitHub username.", "validation", false
31+
);
32+
33+
return false;
34+
}
35+
}
36+
}

registration/code/infrastructure/active_records/OpenStackMember.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class OpenStackMember
2626
'Bio' => 'HTMLText',
2727
'FoodPreference' => 'Text',
2828
'OtherFood' => 'Text',
29+
'GitHubUser' => 'Text',
2930
'IRCHandle' => 'Text',
3031
'TwitterName' => 'Text',
3132
'Projects' => 'Text',
@@ -99,6 +100,7 @@ public function onBeforeWrite()
99100
$this->owner->SecondEmail = trim($this->owner->SecondEmail);
100101
$this->owner->ThirdEmail = trim($this->owner->ThirdEmail);
101102
$this->owner->StatementOfInterest = trim($this->owner->StatementOfInterest);
103+
$this->owner->GitHubUser = trim($this->owner->GitHubUser);
102104
$this->owner->IRCHandle = trim($this->owner->IRCHandle);
103105
$this->owner->TwitterName = trim($this->owner->TwitterName);
104106
$this->owner->LinkedInProfile = trim($this->owner->LinkedInProfile);

registration/code/ui/forms/EditProfileForm.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ function __construct($controller, $name)
8787
$OtherFoodField = new TextField('OtherFood', 'Other Food Considerations');
8888
$OtherFoodField->addExtraClass('other-field');
8989

90-
// IRC and Twitter
90+
// Github, IRC and Twitter
91+
$GitHubUserField = new GitHubUserField('GitHubUser', 'GitHub User <em>(Optional)</em>');
9192
$IRCHandleField = new TextField('IRCHandle', 'IRC Handle <em>(Optional)</em>');
9293
$TwitterNameField = new TextField('TwitterName', 'Twitter Name <em>(Optional)</em>');
9394
$LinkedInProfileField = new TextField('LinkedInProfile', 'LinkedIn Profile - full URL <em>(Optional)</em>');
@@ -178,6 +179,7 @@ function __construct($controller, $name)
178179
new LiteralField('instructions',
179180
'<p>Your statement of interest should be a few words describing your objectives or plans for OpenStack.</p>'),
180181
new LiteralField('break', '<hr/>'),
182+
$GitHubUserField,
181183
$IRCHandleField,
182184
$TwitterNameField,
183185
$LinkedInProfileField,

registration/javascript/edit.profile.page.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ jQuery(document).ready(function($) {
250250
'Language[4]':{ValidPlainText:true },
251251
'Language[5]':{ValidPlainText:true },
252252
WillingToTravel : {required: true},
253+
'GitHubUser':{ ValidPlainText:true },
253254
'IRCHandle':{ ValidPlainText:true },
254255
'TwitterName':{ ValidPlainText:true }
255256
},

0 commit comments

Comments
 (0)