123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- /**
- * 登录
- **/
- (function($, owner) {
- /**
- * 用户登录
- **/
- owner.login = function(loginInfo, callback) {
- callback = callback || $.noop;
- loginInfo = loginInfo || {};
- loginInfo.account = loginInfo.account || '';
- loginInfo.password = loginInfo.password || '';
- if (loginInfo.account.length < 3) {
- return callback('账号最短为 3 个字符');
- }
- if (loginInfo.password.length < 4) {
- return callback('密码最短为 4 个字符');
- }
-
- $.ajax('http://v2.xinnongbaohe.com/web/application/passport/?login.action?json=1',
- {
- data:
- {
- username:loginInfo.account,
- password:loginInfo.password,
- project:'front'
- },
- dataType:'text',//服务器返回json格式数据
- timeout:10000,//超时时间设置为10秒;
- type:'post',//HTTP请求类型
- success:function(r)
- {
- var t = JSON.parse(r);
- if(t.status == 1)
- {
- return owner.createState(t.account, callback);
- }
- else
- {
- return callback('用户名或密码错误');
- }
- },
- error:function(xhr,type,errorThrown)
- {
- alert(type);
- }
- });
-
- };
- owner.createState = function(name, callback) {
- var state = owner.getState();
- state.account = name;
- state.token = "tokenv2123456789";
- owner.setState(state);
- return callback();
- };
- /**
- * 新用户注册
- **/
- owner.reg = function(regInfo, callback) {
- callback = callback || $.noop;
- regInfo = regInfo || {};
- regInfo.account = regInfo.account || '';
- regInfo.password = regInfo.password || '';
- if (regInfo.account.length < 5) {
- return callback('用户名最短需要 5 个字符');
- }
- if (regInfo.password.length < 6) {
- return callback('密码最短需要 6 个字符');
- }
- if (!checkEmail(regInfo.email)) {
- return callback('邮箱地址不合法');
- }
- var users = JSON.parse(localStorage.getItem('$usersv2') || '[]');
- users.push(regInfo);
- localStorage.setItem('$usersv2', JSON.stringify(users));
- return callback();
- };
- /**
- * 获取当前状态
- **/
- owner.getState = function() {
- var stateText = localStorage.getItem('$statev5') || "{}";
- return JSON.parse(stateText);
- };
- /**
- * 设置当前状态
- **/
- owner.setState = function(state) {
- state = state || {};
- localStorage.setItem('$statev5', JSON.stringify(state));
- //var settings = owner.getSettings();
- //settings.gestures = '';
- //owner.setSettings(settings);
- };
- var checkEmail = function(email) {
- email = email || '';
- return (email.length > 3 && email.indexOf('@') > -1);
- };
- /**
- * 找回密码
- **/
- owner.forgetPassword = function(email, callback) {
- callback = callback || $.noop;
- if (!checkEmail(email)) {
- return callback('邮箱地址不合法');
- }
- return callback(null, '新的随机密码已经发送到您的邮箱,请查收邮件。');
- };
- /**
- * 获取应用本地配置
- **/
- owner.setSettings = function(settings) {
- settings = settings || {};
- localStorage.setItem('$settings', JSON.stringify(settings));
- }
- /**
- * 设置应用本地配置
- **/
- owner.getSettings = function() {
- var settingsText = localStorage.getItem('$settings') || "{}";
- return JSON.parse(settingsText);
- }
- /**
- * 获取本地是否安装客户端
- **/
- owner.isInstalled = function(id) {
- if (id === 'qihoo' && mui.os.plus) {
- return true;
- }
- if (mui.os.android) {
- var main = plus.android.runtimeMainActivity();
- var packageManager = main.getPackageManager();
- var PackageManager = plus.android.importClass(packageManager)
- var packageName = {
- "qq": "com.tencent.mobileqq",
- "weixin": "com.tencent.mm",
- "sinaweibo": "com.sina.weibo"
- }
- try {
- return packageManager.getPackageInfo(packageName[id], PackageManager.GET_ACTIVITIES);
- } catch (e) {}
- } else {
- switch (id) {
- case "qq":
- var TencentOAuth = plus.ios.import("TencentOAuth");
- return TencentOAuth.iphoneQQInstalled();
- case "weixin":
- var WXApi = plus.ios.import("WXApi");
- return WXApi.isWXAppInstalled()
- case "sinaweibo":
- var SinaAPI = plus.ios.import("WeiboSDK");
- return SinaAPI.isWeiboAppInstalled()
- default:
- break;
- }
- }
- }
- }(mui, window.app = {}));
|