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.

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