@@ -0,0 +1,74 @@
/**
* beginnings of a controller to login to system
* here for the purpose of showing how a service might
* be used in an application
*/
angular.module('user.controllers', [])
.controller('LoginController', [
'$state', '$scope', 'UserService', // <-- controller dependencies
function ($state, $scope, UserService) {

debugger;

// ng-model holding values from view/html
$scope.creds = {
username: "adminuser",
password: "password"
};

/**
*
*/
$scope.doLogoutAction = function () {
UserService.logout()
.then(function (_response) {
// transition to next state
$state.go('app-login');
}, function (_error) {
alert("error logging in " + _error.debug);
})
};

/**
*
*/
$scope.doLoginAction = function () {
UserService.login($scope.creds.username, $scope.creds.password)
.then(function (_response) {

alert("login success " + _response.attributes.username);

// transition to next state
$state.go('app.character');

}, function (_error) {
alert("error logging in " + _error.message);
})
};
}])
.controller('SignUpController', [
'$state', '$scope', 'UserService', // <-- controller dependencies
function ($state, $scope, UserService) {

$scope.creds = {};

/**
*
*/
$scope.signUpUser = function () {

UserService.init();

UserService.createUser($scope.creds).then(function (_data) {
$scope.user = _data;
console.log('data', _data);
alert("Success Creating User Account ");

$state.go('app.character', {});

}, function (_error) {
console.log('error', _error);
alert("Error Creating User Account " + _error.debug)
});
}
}]);
@@ -0,0 +1,90 @@
angular.module('user.services', [])

.service('UserService', ['$q', 'ParseConfiguration',
function ($q, ParseConfiguration) {

var parseInitialized = false;


return {

/**
*
* @returns {*}
*/
init: function () {

debugger;
// if initialized, then return the activeUser
if (parseInitialized === false) {
Parse.initialize(ParseConfiguration.applicationId, ParseConfiguration.javascriptKey);
parseInitialized = true;
console.log("parse initialized in init function");
}

var currentUser = Parse.User.current();
if (currentUser) {
return $q.when(currentUser);
} else {
return $q.reject({error: "noUser"});
}

},
/**
*
* @param _userParams
*/
createUser: function (_userParams) {
console.log('params', _userParams);
var user = new Parse.User();
user.set("username", _userParams.email);
user.set("password", _userParams.password);
user.set("email", _userParams.email);
user.set("first_name", _userParams.first_name);
user.set("last_name", _userParams.last_name);

// should return a promise
return user.signUp(null, {});

},
/**
*
* @param _parseInitUser
* @returns {Promise}
*/
currentUser: function (_parseInitUser) {

// if there is no user passed in, see if there is already an
// active user that can be utilized
_parseInitUser = _parseInitUser ? _parseInitUser : Parse.User.current();

console.log("_parseInitUser " + Parse.User.current());
if (!_parseInitUser) {
return $q.reject({error: "noUser"});
} else {
return $q.when(_parseInitUser);
}
},
/**
*
* @param _user
* @param _password
* @returns {Promise}
*/
login: function (_user, _password) {
return Parse.User.logIn(_user, _password);
},
/**
*
* @returns {Promise}
*/
logout: function (_callback) {
var defered = $q.defer();
Parse.User.logOut();
defered.resolve();
return defered.promise;

}

}
}]);

This file was deleted.

@@ -18,9 +18,6 @@ <h1 class="title">Left</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close ng-click="login()">
Login
</ion-item>
<ion-item menu-close href="#/app/character">
Character
</ion-item>
@@ -0,0 +1,19 @@
<ion-view title="Login" hide-back-button="true">
<ion-content padding="true" class="has-header">
<form>
<ion-list>
<label class="item item-input">
<span class="input-label">Username</span>
<input type="text" placeholder="" ng-model="creds.username">
</label>
<label class="item item-input">
<span class="input-label">Password</span>
<input type="password" placeholder="" ng-model="creds.password">
</label>
</ion-list>
<div class="spacer" style="height: 40px;"></div>
<a ng-click="doLoginAction()" class="button button-stable button-block">Log in</a>
<a ui-sref='app-signup' class="button button-positive button-clear button-block">Or create an account</a>
</form>
</ion-content>
</ion-view>
@@ -0,0 +1,26 @@
<ion-view title="Signup">
<ion-content padding="true" scroll="false" class="has-header">
<form>
<ion-list>
<label class="item item-input">
<span class="input-label">First Name</span>
<input type="text" placeholder="First Name" ng-model="creds.first_name">
</label>
<label class="item item-input">
<span class="input-label">Last Name</span>
<input type="text" placeholder="Last Name" ng-model="creds.last_name">
</label>
<label class="item item-input">
<span class="input-label">Username</span>
<input type="text" placeholder="email address" ng-model="creds.email">
</label>
<label class="item item-input">
<span class="input-label">Password</span>
<input type="password" ng-model="creds.password">
</label>
</ion-list>
<button class="button button-stable button-block"
ng-click="signUpUser()">Sign up</button>
</form>
</ion-content>
</ion-view>