Merge branch 'master' of https://github.com/crunchbutton/crunchbutton
This commit is contained in:
commit
dcd0fd0273
@ -2,7 +2,7 @@
|
||||
|
||||
class Controller_api_login extends Crunchbutton_Controller_Rest {
|
||||
public function init() {
|
||||
$user = c::auth()->doAuthByLocalUser(['email' => $this->request()['user'], 'password' => $this->request()['password']]);
|
||||
$user = c::auth()->doAuthByLocalUser(['email' => $this->request()['username'], 'password' => $this->request()['password']]);
|
||||
|
||||
if ($user) {
|
||||
echo c::admin()->json();
|
||||
|
||||
@ -470,6 +470,33 @@ class Crunchbutton_Admin extends Cana_Table {
|
||||
}
|
||||
|
||||
public function exports() {
|
||||
$permissions = [];
|
||||
$groups = [];
|
||||
|
||||
foreach ($this->groups() as $group) {
|
||||
$groups[$group->id_group] = $group->name;
|
||||
}
|
||||
|
||||
if ($this->permission()->_permissions) {
|
||||
foreach ($this->permission()->_permissions as $group => $perms) {
|
||||
foreach ($perms as $key => $value) {
|
||||
if ($value) {
|
||||
$permissions[$key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->permission()->_userPermission) {
|
||||
foreach ($this->permission()->_userPermission as $key => $value) {
|
||||
if ($value) {
|
||||
$permissions[$key] = true;
|
||||
} elseif ($permissions[$key]) {
|
||||
unset($permissions[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ex = [
|
||||
'id_admin' => $this->id_admin,
|
||||
'login' => $this->login,
|
||||
@ -478,7 +505,9 @@ class Crunchbutton_Admin extends Cana_Table {
|
||||
'txt' => $this->txt,
|
||||
'email' => $this->email,
|
||||
'timezone' => $this->timezone,
|
||||
'testphone' => $this->testphone
|
||||
'testphone' => $this->testphone,
|
||||
'permissions' => $permissions,
|
||||
'groups' => $groups
|
||||
];
|
||||
return $ex;
|
||||
}
|
||||
|
||||
@ -66,6 +66,14 @@
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
<li ng-click="account.logout()">
|
||||
<table cellpadding="0" cellspacing="0" class="side-menu-wrap">
|
||||
<tr>
|
||||
<td class="side-menu-icon"><i class="fa fa-wrench"></i></td>
|
||||
<td class="side-menu-label">Sign Out</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
@ -101,26 +109,30 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="login-wrap" ng-controller="LoginCtrl" ng-class="{'logged-in': account.loggedin}">
|
||||
<div class="login-content">
|
||||
<div class="login-wrap" ng-controller="LoginCtrl" ng-class="{'logged-in': account.loggedin}" ng-hide="account.user.id_admin">
|
||||
<div class="login-content hide-before-init">
|
||||
<div class="logo">cockpit<span class="dot">.</span><span class="green">la</span></div>
|
||||
|
||||
|
||||
<div class="input-wrap">
|
||||
<span class="label">Username:</span>
|
||||
<span class="field"><input type="text" name="username" ng-model="user.username" autofocus="autofocus"></span>
|
||||
<div class="dialog-message dialog-message-error" ng-show="error">
|
||||
Invalid username or password
|
||||
</div>
|
||||
|
||||
<div class="input-wrap">
|
||||
<span class="label">Password:</span>
|
||||
<span class="field"><input type="password" name="password" ng-model="user.password"></span>
|
||||
</div>
|
||||
<form ng-submit="login()">
|
||||
<div class="input-wrap">
|
||||
<span class="label">Username:</span>
|
||||
<span class="field"><input type="text" name="username" ng-model="username" autofocus="autofocus"></span>
|
||||
</div>
|
||||
|
||||
<div class="button-pushable find-restaurants">
|
||||
<button class="button orange" ng-click="user.login()">
|
||||
Sign In
|
||||
</button>
|
||||
</div>
|
||||
<div class="input-wrap">
|
||||
<span class="label">Password:</span>
|
||||
<span class="field"><input type="password" name="password" ng-model="password"></span>
|
||||
</div>
|
||||
|
||||
<div class="button-pushable find-restaurants">
|
||||
<button class="button orange">
|
||||
Sign In
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="info">
|
||||
Cockpit is Crunchbutton's tool of awesomeness. Looking for delivery food? Head over to <a href="http://crunchbutton.com">crunchbutton.com</a>
|
||||
|
||||
@ -64,19 +64,10 @@ NGApp.controller('AppController', function ($scope, $route, $http, $routeParams,
|
||||
$rootScope.navigation = MainNavigationService;
|
||||
$rootScope.isPhoneGap = App.isPhoneGap;
|
||||
$rootScope.server = App.server;
|
||||
|
||||
$rootScope.debug = function() {
|
||||
return ( App.config && App.config.user && App.config.user.debug );
|
||||
};
|
||||
$rootScope.account = AccountService;
|
||||
|
||||
$rootScope.$on('userAuth', function(e, data) {
|
||||
$rootScope.$safeApply(function($scope) {
|
||||
// @todo: remove double data
|
||||
if (data) {
|
||||
$rootScope.account.user = data;
|
||||
App.config.user = data;
|
||||
}
|
||||
|
||||
App.snap.close();
|
||||
$rootScope.reload();
|
||||
});
|
||||
|
||||
@ -11,5 +11,11 @@ NGApp.controller( 'SideMenuCtrl', function () {
|
||||
});
|
||||
|
||||
NGApp.controller('LoginCtrl', function($scope, AccountService) {
|
||||
$scope.account = AccountService;
|
||||
$scope.login = function() {
|
||||
AccountService.login($scope.username, $scope.password, function(status) {
|
||||
// $scope.$apply(function() {
|
||||
$scope.error = !status;
|
||||
// })
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -2,14 +2,33 @@ NGApp.factory('AccountService', function($http, $rootScope) {
|
||||
var service = {};
|
||||
|
||||
service.checkUser = function() {
|
||||
if (App.config.user.id_admin) {
|
||||
service.loggedin = true;
|
||||
}
|
||||
service.user = App.config.user;
|
||||
App.config.user = null;
|
||||
};
|
||||
|
||||
service.login = function(user, pass, callback) {
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: App.service + 'login',
|
||||
data: $.param({'username': user, 'password': pass}),
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
}).success(function(data) {
|
||||
if (data && data.id_admin) {
|
||||
service.user = data;
|
||||
$rootScope.$broadcast('userAuth', service.user);
|
||||
callback(true);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
service.logout = function() {
|
||||
$http.get(App.service + 'logout').success(function() {
|
||||
service.user = {};
|
||||
$rootScope.$broadcast('userAuth');
|
||||
})
|
||||
};
|
||||
|
||||
return service;
|
||||
|
||||
});
|
||||
@ -613,3 +613,20 @@ input {
|
||||
box-shadow: none;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.dialog-message {
|
||||
color: #fff;
|
||||
margin-bottom: 1em;
|
||||
border-radius: 4px;
|
||||
font-size: 1.2em;
|
||||
line-height: 1.4em;
|
||||
padding: .7em .9em .5em .9em;
|
||||
}
|
||||
|
||||
.dialog-message-error {
|
||||
background: #e1574c;
|
||||
}
|
||||
|
||||
.dialog-message-success {
|
||||
background: #77c675;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user