Skip to content
jefferscn edited this page Sep 24, 2014 · 1 revision

access.js

where is only one js file in this project,it is so simple.it just do one thing,render a widget to target.

render widget

  function renderWidget(domId,widget,params,target)
  • domId html domid,target to render widget
  • widget widget name(without prefix /widget)
  • params widget params(url query string)
  • target html domid,target when the widget render sub widget,eg:widget is a toolbar item,domid is the toolbar box domid,but when u click this toolbar,there will be another widget to render,'target' is the target.

if u didn't verify the 'target' param,'domId' will be the 'target'

post data

function submitForm(widget,formId,target,param)

post data is another way to render widget.just to render a widget with formdata.

  • widget widget name
  • formId html formId
  • target target domId
  • param additional params(url query string)

server side sample

exports.showLoginForm=function(req,res){
	var params ={};
	params.url=req.query.url;
	params.target = req.query.target;
	if(req.session.logininfo && req.session.logininfo.user){
		//已经登录过
		var redirecturl = '/site/index';
		if(req.query.url && ((req.query.url.indexOf("/site") == 0) ||(req.query.url.indexOf("http") == 0))){
			//redirecturl = queryString.escape(req.query.url);
			//var urlObj = url.parse(redirecturl);
			redirecturl = req.query.url;
			//res.render('account.redirect',{url:urlObj.pathname + urlObj.search?queryString.escape(urlObj.search):''});
		}
		res.render('account.redirect',{url:redirecturl});
		return;
	}
	if(req.query.user){
		var user = req.query.user;
		var pwd = req.query.password;
		req.app.dbSchema.models.User.all({where:{code:user,password:pwd}},function(err,items){
			if(items.length==0){
				params.errMsg = "用户不存在或者密码错误!";
				res.render('account.loginform',params);
				return;
			}
			req.session.logininfo={
				user:items[0]
			};
			var redirecturl = '/site/index';
			if(req.query.url && ((req.query.url.indexOf("/site")==0) ||(req.query.url.indexOf("http") == 0))){
				redirecturl = req.query.url;
//				redirecturl = queryString.escape(req.query.url);
				//var urlObj = url.parse(redirecturl);
				//res.render('account.redirect',{url:urlObj.pathname + urlObj.search?queryString.escape(urlObj.search):''});
			}
			res.render('account.redirect',{url:redirecturl});
			return;
		});
	}else{
		res.render('account.loginform',params);
	}
};

exports.showLoginForm is route of widget showLoginForm,when there is parameter 'user', just render loginform,if not ,do the securiy process.

Clone this wiki locally