Commit 72c499855cc31bc02274a89a6133a94f1915f68b

Testing out Persona code..
  • Diff rendering mode:
  • inline
  • side by side

swtr/static/js/swtmaker.js

7 swtr.sweets = new ImgAnnoSwts();7 swtr.sweets = new ImgAnnoSwts();
8 swtr.appView = new AppView();8 swtr.appView = new AppView();
9 swtr.who = 'Guest';9 swtr.who = 'Guest';
10
11 $.ajaxSetup({
12 xhrFields: {
13 withCredentials: true
14 },
15 crossDomain: true
16 });
10 };17 };
1118
12 /* Model for Image Annotation Sweets */19 /* Model for Image Annotation Sweets */
276 },276 },
277 getSignInCredentials: function(event) {277 getSignInCredentials: function(event) {
278 event.preventDefault();278 event.preventDefault();
279 if(swtr.who === 'Guest' && !$('#username').length) {
279 navigator.id.request();
280 /*if(swtr.who === 'Guest' && !$('#username').length) {
280 var template = _.template($('#signin-credentials-template').html());281 var template = _.template($('#signin-credentials-template').html());
281 $('#signin-msg').html(template());282 $('#signin-msg').html(template());
282 }283 }
285 var username = $('#username').val();285 var username = $('#username').val();
286 var password = $('#password').val();286 var password = $('#password').val();
287 this.signIn(username, password);287 this.signIn(username, password);
288 }
288 }*/
289 return false;289 return false;
290 },290 },
291 signIn: function(username, password) {291 signIn: function(username, password) {
310 }310 }
311 }311 }
312 });312 });
313 },
314 userLoggedIn: function(userData) {
315 swtr.who = userData.username;
316 var text = 'You are signed in as <b>' + swtr.who+ '</b>';
317 $('#signinview').html(text);
318 },
319 userLoggedOut: function() {
320 swtr.who = 'Guest';
321 $('#signinview').html('Logged out');
313 }322 }
314 });323 });
315324
362362
363 //swtr.AppView = AppView;363 //swtr.AppView = AppView;
364364
365 /*navigator.watch({
365 // Persona callbacks
366 navigator.id.watch({
367 //when an user logs in
366 onlogin: function(assertion) {368 onlogin: function(assertion) {
369 //verify assertion and login the user
367 $.ajax({370 $.ajax({
368 type: 'POST',371 type: 'POST',
369 url: swtr.swtstoreURL() + swtr.endpoints.login,372 url: swtr.swtstoreURL() + swtr.endpoints.login,
370 data: {assertion: assertion},373 data: {assertion: assertion},
371 success: function() {
374 success: function(data) {
375 console.log('user logged in', data);
376 swtr.appView.userLoggedIn(data);
372 },377 },
373 error: function() {378 error: function() {
374 navigator.id.logout();379 navigator.id.logout();
375 }380 }
376 });381 });
377 },382 },
383 //when an user logs out
378 onlogout: function() {384 onlogout: function() {
379 $.ajax({385 $.ajax({
380 type: 'POST',386 type: 'POST',
387 //data: {email: swtr.who},
381 url: swtr.swtstoreURL() + swtr.endpoints.logout,388 url: swtr.swtstoreURL() + swtr.endpoints.logout,
382 success: function() {389 success: function() {
390 console.log('user logged out');
391 //swtr.appView.userLoggedOut();
383 },392 },
384 error: function() {393 error: function() {
385 }394 }
386 });395 });
387 }396 }
388 });*/
397 });
389398
390})(swtr);399})(swtr);

swtr/templates/index.html

53 window.swtr = window.swtr || {};53 window.swtr = window.swtr || {};
54 swtr.swtstoreURL = function() { return '{{ conf.swtstoreURL }}'; }54 swtr.swtstoreURL = function() { return '{{ conf.swtstoreURL }}'; }
55 swtr.endpoints = {'get': '/sweets/q', 'post': '/sweets', 'auth':55 swtr.endpoints = {'get': '/sweets/q', 'post': '/sweets', 'auth':
56 '/authenticate'};
56 '/authenticate', 'login': '/auth/login', 'logout': '/auth/logout'};
57 window.onload = function() {57 window.onload = function() {
58 swtr.init();58 swtr.init();
59 };59 };
64 <script src="{{ url_for('static', filename='js/lib/backbone-1.0.0.min.js') }}"></script>64 <script src="{{ url_for('static', filename='js/lib/backbone-1.0.0.min.js') }}"></script>
65 <script src="{{ url_for('static', filename='js/lib/annotorious.debug.js') }}"></script>65 <script src="{{ url_for('static', filename='js/lib/annotorious.debug.js') }}"></script>
66 <!--script src="https://login.persona.org/include.js"></script-->66 <!--script src="https://login.persona.org/include.js"></script-->
67 <script src="{{ url_for('static', filename='js/lib/mozilla.persona.include.js') }}"></script>
67 <script src="{{ url_for('static', filename='js/swtmaker.js') }}"></script>68 <script src="{{ url_for('static', filename='js/swtmaker.js') }}"></script>
6869
69 <script type="text/template" id="sweet-template">70 <script type="text/template" id="sweet-template">