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.

113 lines
3.2 KiB

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