Guest User

Untitled

a guest
Jan 14th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. angular.module('MAJ').controller('LoginCtrl', function ($scope, $http, $timeout, maj, router, debug, login, utils) {
  2.  
  3. $scope.autoLoginPossible = login.autoLoginPossible();
  4.  
  5. if ($scope.autoLoginPossible) {
  6. $scope.autoLoginData = login.getAutoLoginData();
  7. $scope.makeUserAvatar = utils.makeUserAvatar;
  8. }
  9.  
  10.  
  11. $scope.login = function (form) {
  12. if (form.$invalid) {
  13. maj.framework7.alert('Bitte gib deine Logindaten ein');
  14. return;
  15. }
  16.  
  17.  
  18. $http.apiRequest('login', {
  19. username: form.username.$viewValue,
  20. password: form.password.$viewValue,
  21. app_id: maj.push.id
  22. })
  23. .then(function (response) {
  24. if (! response.data.response) {
  25. maj.framework7.alert('Falscher Benutzername und/oder Passwort.');
  26. debug(response.data.message);
  27. }
  28. else {
  29. login.loginWithResponse(response.data);
  30. router.redirect('dashboard.html');
  31. }
  32. });
  33. };
  34.  
  35.  
  36. $scope.facebookLogin = function () {
  37. var unknownLoginErrorString = 'Es ist ein Fehler beim Facebook Login aufgetreten.';
  38.  
  39. facebookConnectPlugin.login(['public_profile'],
  40. function (userData) {
  41. $http.apiRequest('fblogin', {
  42. fbuser: btoa( JSON.stringify(userData) ),
  43. app_id: maj.push.id
  44. }).then(
  45. function (response) {
  46. // we show the unknown error instead of the real one to hide that information from
  47. // the user.
  48. if (! response.data.response) {
  49. maj.framework7.alert(unknownLoginErrorString);
  50. debug('Facebook Login', response.data);
  51. }
  52. else {
  53. login.loginWithResponse(response.data);
  54. router.redirect('dashboard.html');
  55. }
  56. }
  57. )
  58. },
  59. function (error) {
  60. maj.framework7.alert(unknownLoginErrorString);
  61. debug('Facebook Login', error)
  62. }
  63. )
  64. };
  65.  
  66.  
  67. $scope.clearAutoLogin = function () {
  68. login.clearLoginData();
  69. $scope.autoLoginPossible = false;
  70. };
  71.  
  72.  
  73. $scope.doAutoLogin = function () {
  74. $http.apiRequest('get_logged_user', { loginhash: $scope.autoLoginData.hash }).then(function (response) {
  75. login.loginWithResponse(response.data);
  76. router.redirect('dashboard.html');
  77. });
  78. };
  79.  
  80. });
Add Comment
Please, Sign In to add comment