Skip to content
Browse files

Fix messages not showing

  • Loading branch information...
1 parent 5c60771 commit e08b2aa958e146480d8e4871791018df35d84a49 Penn Su committed Jun 29, 2014
Showing with 37 additions and 31 deletions.
  1. +2 −1 www/js/app.js
  2. +21 −14 www/js/controllers.js
  3. +14 −16 www/templates/login.html
View
3 www/js/app.js
@@ -34,7 +34,8 @@ angular.module('starter', ['ionic', 'starter.controllers'])
url: "/message",
views: {
'menuContent' :{
- templateUrl: "templates/message.html"
+ templateUrl: "templates/message.html",
+ controller: 'MessageCtrl'
}
}
})
View
35 www/js/controllers.js
@@ -2,14 +2,21 @@ angular.module('starter.controllers', [])
.constant('spiceRef', new Firebase('https://spicewords.firebaseio.com/'))
-.controller('AppCtrl', function($scope, $ionicModal, $timeout, spiceRef) {
+.controller('AppCtrl', function($scope, $location, $ionicModal, $timeout, spiceRef) {
// Form data for the login modal
$scope.loginData = {};
$scope.loginStatus = {
status: 'logout'
};
- var auth = new FirebaseSimpleLogin(spiceRef, function (error, user) {
+ // Create the login modal that we will use later
+ $ionicModal.fromTemplateUrl('templates/login.html', {
+ scope: $scope
+ }).then(function(modal) {
+ $scope.modal = modal;
+ });
+
+ $scope.auth = new FirebaseSimpleLogin(spiceRef, function (error, user) {
if (error) {
console.log(error);
alert(error);
@@ -35,13 +42,6 @@ angular.module('starter.controllers', [])
}
});
- // Create the login modal that we will use later
- $ionicModal.fromTemplateUrl('templates/login.html', {
- scope: $scope
- }).then(function(modal) {
- $scope.modal = modal;
- });
-
// Triggered in the login modal to close it
$scope.closeLogin = function() {
$scope.modal.hide();
@@ -53,19 +53,26 @@ angular.module('starter.controllers', [])
};
// Perform the login action when the user submits the login form
- $scope.doLogin = function() {
+ $scope.doLogin = function (data) {
console.log('Doing login', $scope.loginData);
if ($scope.loginStatus.status == 'logout') {
- auth.login('password', $scope.loginData);
+ $scope.auth.login('password', $scope.loginData);
}
};
- $scope.doSignup = function () {
- auth.createUser($scope.loginData.email, $scope.loginData.password, function (error, user) {
+ $scope.doSignup = function (data) {
+ console.log('Doing signup', $scope.loginData);
+
+ $scope.auth.createUser($scope.loginData.email, $scope.loginData.password, function (error, user) {
if (!error) {
console.log('User Id: ' + user.uid + ', Email: ' + user.email);
- auth.login('password', $scope.loginData);
+ //$scope.auth.login('password', $scope.loginData);
+ } else {
+ console.log(error);
+ alert(error);
+ $scope.loginStatus.error = error;
+ $scope.loginStatus.status = 'error'
}
});
};
View
30 www/templates/login.html
@@ -6,22 +6,20 @@ <h1 class="title">Login</h1>
</div>
</ion-header-bar>
<ion-content>
- <form name="form" ng-submit="doLogin()">
- <div class="list">
- <label class="item item-input">
- <span class="input-label">Email</span>
- <input type="text" ng-model="loginData.email" required>
- </label>
- <label class="item item-input">
- <span class="input-label">Password</span>
- <input type="password" ng-model="loginData.password" required>
- </label>
- <label class="item">
- <button class="button button-positive" type="submit" ng-disabled="form.$invalid" ng-click="doLogin(loginData)">Log in</button>
- <button class="button button-balanced" type="submit" ng-disabled="form.$invalid" ng-click="doSignup(loginData)">Sign up</button>
- </label>
- </div>
- </form>
+ <div class="list">
+ <label class="item item-input">
+ <span class="input-label">Email</span>
+ <input type="text" ng-model="loginData.email" required>
+ </label>
+ <label class="item item-input">
+ <span class="input-label">Password</span>
+ <input type="password" ng-model="loginData.password" required>
+ </label>
+ <label class="item">
+ <a class="button button-positive" ng-disabled="form.$invalid" ng-click="doLogin(loginData)">Log in</a>
+ <a class="button button-balanced" ng-disabled="form.$invalid" ng-click="doSignup(loginData)">Sign up</a>
+ </label>
+ </div>
</ion-content>
</div>

0 comments on commit e08b2aa

Please sign in to comment.
Something went wrong with that request. Please try again.