forked from allevaton/starterupper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
351 lines (342 loc) · 14.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Git and Hosting Setup</title>
<!-- Suppress favicon -->
<link rel="shortcut icon" href="#" />
<link rel="stylesheet" href="http://lawrancej.github.io/starterupper/reset.css" />
<link rel="stylesheet" href="http://lawrancej.github.io/starterupper/text.css" />
<link rel="stylesheet" href="http://lawrancej.github.io/starterupper/960.css" />
<style>
h1 {margin:0px; padding:0px;}
hgroup div {position: relative; top: 50%; transform: translateY(70%);}
</style>
<script src="http://lawrancej.github.io/starterupper/ractive-legacy.min.js"></script>
<script src="http://lawrancej.github.io/starterupper/sparkMD5.js"></script>
<script src="http://lawrancej.github.io/starterupper/jquery-2.1.1.min.js"></script>
<script src="github.js"></script>
</head>
<body>
<article>
<div id="gravatar_container"></div>
<script id="gravatar_template" type="text/ractive">
<div style="display:none;"><img src="http://www.gravatar.com/avatar/{{emailHash}}?d=404" onerror="noGravatarAccount(this)" /></div>
<section class="container_12">
<form method="post" action="/" >
<hgroup>
<h1 class="grid_2">Profile</h1>
<div class="grid_4">Tell git your full name and school email address</div>
<div class="grid_6">
{{#if !gravatarAccount}}
Create or update your Gravatar to help the instructor learn names
{{else}}
Update your Gravatar to help the instructor learn names
{{/if}}
</div>
<div class="clear"></div>
<hr />
</hgroup>
<div class="grid_2"><img src="http://www.gravatar.com/avatar/{{emailHash}}?d=retro&s=140" title="Your Gravatar" width="140" height="140" /></div>
<div class="grid_4">
<input type="text" name="user.name" value="{{fullName}}" placeholder="Full name" pattern="[a-zA-Z.]+ [a-zA-Z. ]+" required /><br />
<input type="email" name="user.email" value="{{email}}" placeholder="School email address" required autofocus /><br />
<button>Configure Git</button>
<pre>
git config --global user.name "{{fullName}}"
git config --global user.email "{{email}}"</pre>
</div>
<div class="grid_6">
{{#if gravatarAccount }}
Thanks for creating a Gravatar! (<a href="https://en.gravatar.com/gravatars/new" target="actionRequired">Update</a>)
{{else}}
<ol>
<li><a href="https://en.gravatar.com/emails/new" target="actionRequired">Add email to Gravatar account</a> or <a href="https://en.gravatar.com/connect/?source=_signup" target="actionRequired">join Gravatar</a><br />
(use {{emailPrompt}})</li>
<li>Gravatar will email a link: click to verify your school email</li>
<li><a href="https://en.gravatar.com/gravatars/new" target="actionRequired">Add an image</a></li>
</ol>
{{/if}}
</div>
</form>
</section>
<br />
<form>
<input type="hidden" name="user.name" value="{{fullName}}" />
<input type="hidden" name="user.email" value="{{email}}" />
<section class="container_12">
<hgroup>
<h1 class="grid_2">Github</h1>
<div class="grid_4">Github hosts private repositories free for students</div>
<div class="grid_6">
{{#if !githubLoggedIn}}
Create or upgrade your Github account for educational use
{{else}}
{{#if !githubUpgradedPlan}}
Upgrade your Github account for educational use
{{else}}
Thanks for setting up your Github account!
{{/if}}
{{/if}}
</div>
<div class="clear"></div>
<hr />
</hgroup>
<div class="clear"></div>
<div class="grid_2"><img src="http://lawrancej.github.io/starterupper/github.svg" width="140" height="140" /></div>
<div class="grid_4">
{{#if githubLoggedIn}}
You are signed into Github <button>Sign out</button>
{{else}}
<input type="text" name="github.login" value="{{githubUsername}}" placeholder="Github username" pattern="^[0-9a-zA-Z][0-9a-zA-Z-]*$" required /><br />
<input type="password" id="password" placeholder="Password" pattern=".{7,}" required /><br />
{{#if githubTwoFactor}}
<input type="text" id="otp" placeholder="Authentication code" pattern="[0-9]{6}" required /><br />
{{/if}}
<input type="button" onclick="login(this);" value="Sign in" /> <a href="https://github.com/password_reset">Forgot password?</a>
{{/if}}
</div>
<div class="grid_6">
<ol>
{{#if githubLoggedIn}}
{{#if !githubEmailFound}}
<li><a href="https://github.com/settings/emails" target="actionRequired">Add & verify your email with Github</a></li>
{{/if}}
{{else}}
{{#if !githubEmailFound}}
<li><b>Github users:</b> <a href="https://github.com/settings/emails" target="actionRequired"> Add & verify your email</a> <br />
<b>New to Github?</b> <a href="https://github.com/join" target="actionRequired">Join</a>
(use {{emailPrompt}})</li>
{{/if}}
{{/if}}
{{#if !githubVerifiedEmail}}
<li>Github will email a link: click to verify your school email</li>
{{/if}}
{{#if !githubUpgradedPlan}}
<li><a href="https://education.github.com/discount_requests/new" target="actionRequired">Request an individual student discount</a></li>
{{/if}}
</ol>
</div>
</section>
<br />
<section class="container_12">
<hgroup>
<h1 class="grid_2">Git Setup</h1>
<div class="grid_10">Set up your git repositories: <b>local</b> (<a href="{{localRepo}}" target="_blank"><code>~/{{repo}}</code></a>), <b>origin</b> (<a href="https://github.com/{{githubUsername}}/{{repo}}" target="_blank">your private repository</a>), and <b>upstream</b> (<a href="https://github.com/{{githubInstructorLogin}}/{{repo}}" target="_blank">course repository</a>)</div>
<div class="clear"></div>
<hr />
</hgroup>
<div class="clear"></div>
<div class="grid_2"><img src="http://lawrancej.github.io/starterupper/git.svg" width="140" height="140" /></div>
<div class="grid_10">
<button>Set up {{repo}}</button>
<pre>git clone https://github.com/{{githubInstructorLogin}}/{{repo}}.git
cd {{repo}}
git remote rm origin
git remote add origin [email protected]:{{githubUsername}}/{{repo}}.git
git remote add upstream https://github.com/{{githubInstructorLogin}}/{{repo}}.git
git push -u origin master</pre>
</div>
</section>
</form>
</script>
</article>
<script>
var ractive = new Ractive({
// The `el` option can be a node, an ID, or a CSS selector.
el: 'gravatar_container',
// We could pass in a string, but for the sake of convenience
// we're passing the ID of the <script> tag above.
template: '#gravatar_template',
// Here, we're passing in some initial data
data: {
// Name of the repository only
repo: 'REPOSITORY',
// file:// path to local repository
localRepo: 'LOCAL_REPO',
// User's full name
fullName: 'FULL_NAME',
// User's OS username
localUsername: 'USER_NAME',
// User's login at their machine
hostLogin: 'USER_NAME@HOSTNAME',
// User's public key
publicKey: 'PUBLIC_KEY',
// User's email
email: 'USER_EMAIL',
// Is the user's email valid?
validEmail: false,
// Is the user's email a school email?
schoolEmail: false,
// Gravatar ID
emailHash: SparkMD5.hash('USER_EMAIL'),
// Did we find a Gravatar image from the user's email? (Assume yes unless we get a 404 error)
gravatarAccount: true,
// Email placeholder
emailPrompt: 'USER_EMAIL',
// What's the username?
githubUsername: 'GITHUB_LOGIN',
// Who's the instructor?
githubInstructorLogin: 'INSTRUCTOR_GITHUB',
// Successful Github login?
githubLoggedIn: false,
// Does Github need two-factor auth?
githubTwoFactor: false,
// Is the email on the account?
githubEmailFound: false,
// Is the Github email verified?
githubVerifiedEmail: false,
// Can we create a private repository?
githubUpgradedPlan: false,
// Did we create a private repository?
githubRepositoryCreated: false,
// Did we add a collaborator?
githubCollaboratorAdded: false,
// Did we share the public key?
githubPublicKeyShared: false,
// Did we share the full name?
githubFullNameShared: false
}
});
ractive.observe('email', function ( newValue, oldValue ) {
var newEmail=newValue.toLowerCase().trim();
var regex=/edu$/;
var emailValid=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
var validEmail=emailValid.test(newEmail);
var schoolEmail=regex.test(newEmail);
ractive.set('validEmail',validEmail);
ractive.set('schoolEmail',schoolEmail);
ractive.set('email',newEmail);
ractive.set('emailHash', SparkMD5.hash(newEmail));
ractive.set('emailPrompt', (validEmail && schoolEmail) ? newEmail: "your school email");
ractive.set('gravatarAccount',validEmail && schoolEmail);
});
function noGravatarAccount(source) {
ractive.set('gravatarAccount', false);
}
function setupUser() {
// Setup user profile
Github.getUser({
success: function(response) {
// Nag the user if they're not on an upgraded plan
if (response.plan.name.toLowerCase() != "free") {
ractive.set('githubUpgradedPlan', true);
} else {
ractive.set('githubUpgradedPlan', false);
}
// Set the user name for the instructor's benefit
if (response.hasOwnProperty("name") && response.name != ractive.get('fullName')) {
Github.setUser({
data: {
name: ractive.get('fullName')
},
success: function(response) {
ractive.set('githubFullNameShared', true);
},
fail: function(response) {
ractive.set('githubFullNameShared', false);
}
});
}
// Set the company for the instructor's benefit
// TODO: http://www.whoisxmlapi.com/whois-api-doc.php
/*
if (response.hasOwnProperty("company") && response.company == "") {
Github.setUser({
data: {company: ""},
success: function(response) {},
fail: function(response) {
// TODO: tell the user what to do if this breaks
}
});
}
*/
}
});
}
function setupEmail() {
// Setup email
Github.getEmail({
email: ractive.get('email'),
added: function() {
ractive.set('githubEmailFound', true);
},
verified: function() {
ractive.set('githubVerifiedEmail', true);
},
unverified: function() {
ractive.set('githubVerifiedEmail', false);
},
missing: function() {
// The user needs to verify their email
ractive.set('githubVerifiedEmail', false);
Github.setEmail({
email: ractive.get('email'),
success: function() {
ractive.set('githubEmailFound', true);
},
fail: function() {
ractive.set('githubEmailFound', false);
}
});
}
});
}
function setupSSH() {
Github.shareKey({
title: ractive.get('hostLogin'),
key: ractive.get('publicKey'),
success: function() {
ractive.set('githubPublicKeyShared', true);
},
fail: function() {
ractive.set('githubPublicKeyShared', false);
}
});
}
function setupRepo() {
Github.createRepo({
login: ractive.get('githubUsername'),
repo: ractive.get('repo'),
success: function(response) {
ractive.set('githubRepositoryCreated', true);
},
fail: function(response) {
ractive.set('githubRepositoryCreated', false);
}
});
Github.addCollaborator({
login: ractive.get('githubUsername'),
repo: ractive.get('repo'),
collaborator: ractive.get('githubInstructorLogin'),
success: function(response) {
ractive.set('githubCollaboratorAdded', true);
},
fail: function(response) {
ractive.set('githubCollaboratorAdded', false);
}
});
}
function login(event) {
Github.login({
username: ractive.get('githubUsername'),
password: $("#password").val(),
otp: $("#otp").val(),
authenticated: function() {
ractive.set('githubLoggedIn', true);
setupUser();
setupEmail();
// setupSSH();
setupRepo();
},
badCredential: function() {
$("#password").attr('value', '');
},
twoFactor: function() {
ractive.set('githubTwoFactor', true);
}
});
}
</script>
</body>
</html>