本教程在第一部分构建,在该部分中,我们使用Onsen UI创建了用于登录和注册页面的用户界面。 现在,我们将使用AngularJS和Firebase作为后端添加功能。 完整的源代码可在GitHub上找到。
>密钥概念:
FirebaseSimpleLogin
教程涵盖了基于Firebase的用户注册,包括电子邮件/密码验证,使用auth.createUser
克隆教程的源代码并安装依赖项:
>在
上访问该应用程序或使用Android Emulator。git clone https://github.com/sitepoint-examples/OnsenUI--Part1 cd OnsenUI--Part1 npm install npm install -g gulp gulp serve
>实现登录:
添加 >
登记为firebase帐户并获取您的firebase URL(例如 实例:>
>
创建
>在注册页面中的电子邮件和密码字段中添加指令:
>
添加模态以进行注册验证错误,类似
结论: 以上是使用Onsen UI将您的Cordova应用程序进一步的详细内容。更多信息请关注PHP中文网其他相关文章!http://localhost:8901/index.html
/OnsenUI--Part1/www/js/app.js
(function() {
'use strict';
var module = angular.module('app', ['onsen']);
module.controller('AppController', function($scope) {
$scope.data = [];
$scope.SignIn = function() {
var user = $scope.data.username;
var pass = $scope.data.password;
if (user && pass) {
// Firebase authentication
auth.login('password', { email: user, password: pass });
} else {
// Show validation modal
modal.show();
}
};
// ... (rest of the controller)
});
})();
ng-model
登录按钮的index.html
事件触发<input ng-model="data.username" type="text" placeholder="Username" ... />
<input ng-model="data.password" type="password" placeholder="Password" ... />
index.html
<ons-modal var="modal" ng-click="modal.hide()">
Invalid Username or Password.
</ons-modal>
ng-click
)。 在SignIn()
>中包括firebase和firebase简单登录脚本
<ons-button id="btnSignIn" modifier="large" ng-click="SignIn()">SignIn</ons-button>
https://your-firebase-app.firebaseio.com
index.html
主页和注销:<🎜>
<🎜>
FirebaseSimpleLogin
:app.js
var firebaseRef = new Firebase('YOUR_FIREBASE_URL');
var auth = new FirebaseSimpleLogin(firebaseRef, function(error, user) {
if (!error && user) {
$scope.username = user.email;
myNavigator.pushPage('home.html', { animation: 'slide' });
$scope.$apply(); // Ensure Angular updates the view
}
});
home.html
在<ons-template id="home.html">
<ons-page>
<!-- ... content ... -->
<ons-icon icon="ion-log-out" ng-click="logout()">Logout</ons-icon>
</ons-page>
</ons-template>
logout
app.js
> $scope.logout = function() {
auth.logout();
$scope.data = [];
myNavigator.popPage();
$scope.$apply(); // Ensure Angular updates the view
};
git clone https://github.com/sitepoint-examples/OnsenUI--Part1
cd OnsenUI--Part1
npm install
npm install -g gulp
gulp serve