Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. //Reddit authentication
  2. const remote = require('electron').remote;
  3. const BrowserWindow = remote.BrowserWindow;
  4. const snoowrap = require('snoowrap');
  5. var apiCode;
  6.  
  7. const m = new snoowrap({
  8. userAgent: 'snooredditclient:v1.0.0 (by /u/enejo1)',
  9. clientId: '{clientid}',
  10. clientSecret: '',
  11. refreshToken: '',
  12. redirectUri: 'http://google.com'
  13. });
  14.  
  15. function myBoi() {
  16. let myNotification = new Notification('You have recieved a message', {
  17. body: 'Message content goes here'
  18. })
  19. }
  20.  
  21. var app = angular.module('snoo-app', ['ngRoute']);
  22.  
  23. app.config(function($routeProvider) {
  24. $routeProvider
  25. .when('/', {
  26. templateUrl: './pages/home.html'
  27. })
  28. .when('/info', {
  29. templateUrl: './pages/info.html'
  30. })
  31. .when('/test', {
  32. templateUrl: './pages/testpage.html'
  33. })
  34. .when('/account', {
  35. templateUrl: './pages/account.html'
  36. })
  37. .when('/signin', {
  38. templateUrl: './pages/sign-in.html'
  39. })
  40. });
  41.  
  42.  
  43. //All reddit stuff
  44. function auth() {
  45.  
  46. var win = new BrowserWindow({ width: 850, height: 600, frame: false });
  47.  
  48. var authURL = snoowrap.getAuthUrl({
  49. clientId: '{clientid}',
  50. scope: ['account', 'edit', 'history', 'identity', 'modflair', 'modlog', 'modmail', 'modposts', 'modself', 'modwiki', 'mysubreddits', 'privatemessages', 'read', 'report', 'save', 'submit', 'subscribe', 'vote', 'wikiedit', 'wikiread'],
  51. redirectUri: 'http://google.com',
  52. permanent: true,
  53. state: 'somevalue'
  54. });
  55.  
  56. win.loadURL(authURL);
  57. win.webContents.on('did-stop-loading', function(event, oldUrl, newUrl, isMainFrame) {
  58. win.show();
  59. if (win.webContents.getURL().includes('&code=')) {
  60. apiCode = win.webContents.getURL().substring(45);
  61. console.log(apiCode);
  62. win.close();
  63. setup();
  64. }
  65. });
  66. }
  67.  
  68. function setup() {
  69. m.fromAuthCode({
  70. code: apiCode,
  71. userAgent: 'snooredditclient:v1.0.0 (by /u/enejo1)',
  72. clientId: '{clientid}',
  73. redirectUri: 'http://google.com'
  74. })
  75.  
  76. m.getMe().then(console.log);
  77. return m.getMe().fetch().then(userInfo => {
  78. console.log(userInfo.name);
  79. document.getElementById('userAccountName').innerText = userInfo.name;
  80. document.getElementById('userKarma').innerText = userInfo.link_karma;
  81. });
  82. }
  83.  
  84. function myDude() {
  85. return m.getMe().fetch().then(userInfo => {
  86. console.log(userInfo.name);
  87. });
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement