Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('MAJ').controller('LoginCtrl', function ($scope, $http, $timeout, maj, router, debug, login, utils) {
- $scope.autoLoginPossible = login.autoLoginPossible();
- if ($scope.autoLoginPossible) {
- $scope.autoLoginData = login.getAutoLoginData();
- $scope.makeUserAvatar = utils.makeUserAvatar;
- }
- $scope.login = function (form) {
- if (form.$invalid) {
- maj.framework7.alert('Bitte gib deine Logindaten ein');
- return;
- }
- $http.apiRequest('login', {
- username: form.username.$viewValue,
- password: form.password.$viewValue,
- app_id: maj.push.id
- })
- .then(function (response) {
- if (! response.data.response) {
- maj.framework7.alert('Falscher Benutzername und/oder Passwort.');
- debug(response.data.message);
- }
- else {
- login.loginWithResponse(response.data);
- router.redirect('dashboard.html');
- }
- });
- };
- $scope.facebookLogin = function () {
- var unknownLoginErrorString = 'Es ist ein Fehler beim Facebook Login aufgetreten.';
- facebookConnectPlugin.login(['public_profile'],
- function (userData) {
- $http.apiRequest('fblogin', {
- fbuser: btoa( JSON.stringify(userData) ),
- app_id: maj.push.id
- }).then(
- function (response) {
- // we show the unknown error instead of the real one to hide that information from
- // the user.
- if (! response.data.response) {
- maj.framework7.alert(unknownLoginErrorString);
- debug('Facebook Login', response.data);
- }
- else {
- login.loginWithResponse(response.data);
- router.redirect('dashboard.html');
- }
- }
- )
- },
- function (error) {
- maj.framework7.alert(unknownLoginErrorString);
- debug('Facebook Login', error)
- }
- )
- };
- $scope.clearAutoLogin = function () {
- login.clearLoginData();
- $scope.autoLoginPossible = false;
- };
- $scope.doAutoLogin = function () {
- $http.apiRequest('get_logged_user', { loginhash: $scope.autoLoginData.hash }).then(function (response) {
- login.loginWithResponse(response.data);
- router.redirect('dashboard.html');
- });
- };
- });
Add Comment
Please, Sign In to add comment