You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.4 KiB

  1. <div class="narrow">
  2. <?= partial('partials/header') ?>
  3. <h2>Signed In As</h2>
  4. <code><?= session('me') ?></code>
  5. <h3>Facebook</h3>
  6. <input type="button" id="facebook-button" value="Checking" class="btn">
  7. <h3>Twitter</h3>
  8. <input type="button" id="twitter-button" value="Checking" class="btn">
  9. <!--
  10. <h3>Instagram</h3>
  11. -->
  12. </div>
  13. <script>
  14. window.quillFbInit = function() {
  15. FB.getLoginStatus(function(response) {
  16. if (response.status === 'connected') {
  17. // the user is logged in and has authenticated your
  18. // app, and response.authResponse supplies
  19. // the user's ID, a valid access token, a signed
  20. // request, and the time the access token
  21. // and signed request each expire
  22. var uid = response.authResponse.userID;
  23. var accessToken = response.authResponse.accessToken;
  24. save_facebook_token(response.authResponse.accessToken);
  25. } else if (response.status === 'not_authorized') {
  26. // the user is logged in to Facebook,
  27. // but has not authenticated your app
  28. console.log("Logged in but not authorized");
  29. $("#facebook-button").val("Sign In").addClass("btn-warning");
  30. } else {
  31. // the user isn't logged in to Facebook.
  32. console.log("User isn't logged in");
  33. $("#facebook-button").val("Sign In").addClass("btn-warning");
  34. }
  35. });
  36. };
  37. window.quillHandleFbLogin = function(response) {
  38. save_facebook_token(response.authResponse.accessToken);
  39. };
  40. function save_facebook_token(token) {
  41. console.log("Authed with token: " + token);
  42. $.post('/auth/facebook', {
  43. fb_token: token
  44. }, function(data){
  45. $("#facebook-button").val("Connected").addClass("btn-success");
  46. });
  47. }
  48. $(function(){
  49. $.getJSON("/auth/twitter", function(data){
  50. // Check if we're already authorized with twitter
  51. if(data && data.result == 'ok') {
  52. $("#twitter-button").val("Connected").addClass("btn-success");
  53. } else if(data && data.url) {
  54. $("#twitter-button").val("Sign In").data("url", data.url).addClass("btn-warning");
  55. } else {
  56. $("#twitter-button").val("Error").addClass("btn-danger");
  57. }
  58. });
  59. $("#twitter-button").click(function(){
  60. if($(this).data('url')) {
  61. window.location = $(this).data('url');
  62. } else {
  63. $.getJSON("/auth/twitter", {login: 1}, function(data){
  64. window.location = data.url;
  65. });
  66. }
  67. });
  68. $("#facebook-button").click(function(){
  69. FB.login(window.quillHandleFbLogin, {scope:'publish_actions'});
  70. });
  71. });
  72. </script>