|  |  | @ -4,14 +4,18 @@ import ( | 
			
		
	
		
			
				
					|  |  |  | 	"GoClouds/cloud/sysCloud" | 
			
		
	
		
			
				
					|  |  |  | 	"GoClouds/core/bean" | 
			
		
	
		
			
				
					|  |  |  | 	"GoClouds/core/comm" | 
			
		
	
		
			
				
					|  |  |  | 	"GoClouds/core/utils" | 
			
		
	
		
			
				
					|  |  |  | 	"GoClouds/models" | 
			
		
	
		
			
				
					|  |  |  | 	"GoClouds/service" | 
			
		
	
		
			
				
					|  |  |  | 	"GoClouds/service/userService" | 
			
		
	
		
			
				
					|  |  |  | 	"encoding/json" | 
			
		
	
		
			
				
					|  |  |  | 	"fmt" | 
			
		
	
		
			
				
					|  |  |  | 	"github.com/donnie4w/go-logger/logger" | 
			
		
	
		
			
				
					|  |  |  | 	"github.com/go-macaron/cache" | 
			
		
	
		
			
				
					|  |  |  | 	gocloud "github.com/mgr9525/go-cloud" | 
			
		
	
		
			
				
					|  |  |  | 	ruisUtil "github.com/mgr9525/go-ruisutil" | 
			
		
	
		
			
				
					|  |  |  | 	"gopkg.in/macaron.v1" | 
			
		
	
		
			
				
					|  |  |  | 	"gopkg.in/mgo.v2/bson" | 
			
		
	
		
			
				
					|  |  |  | 	"strings" | 
			
		
	
		
			
				
					|  |  |  | 	"time" | 
			
		
	
		
			
				
					|  |  |  | ) | 
			
		
	
	
		
			
				
					|  |  | @ -24,6 +28,7 @@ func (e *UserController) GetPath() string { | 
			
		
	
		
			
				
					|  |  |  | func (e *UserController) Routes() { | 
			
		
	
		
			
				
					|  |  |  | 	gocloud.Web.Any("/info", e.info) | 
			
		
	
		
			
				
					|  |  |  | 	gocloud.Web.Any("/login", e.login) | 
			
		
	
		
			
				
					|  |  |  | 	gocloud.Web.Any("/reg", e.reg) | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | func (e *UserController) Mid() []macaron.Handler { | 
			
		
	
		
			
				
					|  |  |  | 	return []macaron.Handler{gocloud.AccessAllowFun} | 
			
		
	
	
		
			
				
					|  |  | @ -95,3 +100,56 @@ func (e *UserController) login(c *macaron.Context, ctj gocloud.ContJSON) { | 
			
		
	
		
			
				
					|  |  |  | 	ret.Name = usr.Name | 
			
		
	
		
			
				
					|  |  |  | 	c.JSON(200, ret) | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | func (e *UserController) reg(c *macaron.Context, ctj gocloud.ContJSON) { | 
			
		
	
		
			
				
					|  |  |  | 	phone := ctj.GetString("phone") | 
			
		
	
		
			
				
					|  |  |  | 	pass := ctj.GetString("pass") | 
			
		
	
		
			
				
					|  |  |  | 	nick := ctj.GetString("nick") | 
			
		
	
		
			
				
					|  |  |  | 	if len(phone) <= 0 { | 
			
		
	
		
			
				
					|  |  |  | 		c.PlainText(511, []byte("param err:phone!")) | 
			
		
	
		
			
				
					|  |  |  | 		return | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 	/*if len(pass) <= 0 { | 
			
		
	
		
			
				
					|  |  |  | 		c.PlainText(511, []byte("param err:pass!")) | 
			
		
	
		
			
				
					|  |  |  | 		return | 
			
		
	
		
			
				
					|  |  |  | 	}*/ | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	ret := &bean.SysLogin{} | 
			
		
	
		
			
				
					|  |  |  | 	ne := userService.FindName(phone) | 
			
		
	
		
			
				
					|  |  |  | 	if ne != nil { | 
			
		
	
		
			
				
					|  |  |  | 		ret.Errs = "用户已注册过" | 
			
		
	
		
			
				
					|  |  |  | 		c.JSON(200, ret) | 
			
		
	
		
			
				
					|  |  |  | 		return | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	ne = &models.SysUser{} | 
			
		
	
		
			
				
					|  |  |  | 	ne.Xid = bson.NewObjectId().Hex() | 
			
		
	
		
			
				
					|  |  |  | 	ne.Name = phone | 
			
		
	
		
			
				
					|  |  |  | 	ne.Phone = phone | 
			
		
	
		
			
				
					|  |  |  | 	if len(pass) > 0 { | 
			
		
	
		
			
				
					|  |  |  | 		ne.Pass = strings.ToUpper(ruisUtil.Md5String(pass)) | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 	ne.Times = time.Now() | 
			
		
	
		
			
				
					|  |  |  | 	ne.Logintm = time.Now() | 
			
		
	
		
			
				
					|  |  |  | 	_, err := comm.DbSys.Insert(ne) | 
			
		
	
		
			
				
					|  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  | 		logger.Info("nes SysUser insert err:" + err.Error()) | 
			
		
	
		
			
				
					|  |  |  | 		c.PlainText(512, []byte("插入用户错误!!")) | 
			
		
	
		
			
				
					|  |  |  | 		return | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 	info := &models.MgoUserInfo{} | 
			
		
	
		
			
				
					|  |  |  | 	info.Id = bson.NewObjectId() | 
			
		
	
		
			
				
					|  |  |  | 	info.Uid = ne.Xid | 
			
		
	
		
			
				
					|  |  |  | 	info.Name = ne.Name | 
			
		
	
		
			
				
					|  |  |  | 	if len(nick) > 0 { | 
			
		
	
		
			
				
					|  |  |  | 		info.Nick = nick | 
			
		
	
		
			
				
					|  |  |  | 	} else { | 
			
		
	
		
			
				
					|  |  |  | 		info.Nick = fmt.Sprintf("U%s", utils.GenValidateCode(7)) | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 	service.MgoUserInfoDao.GetSession().C().Insert(info) | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	ret.Stat = 1 | 
			
		
	
		
			
				
					|  |  |  | 	ret.Uid = ne.Id | 
			
		
	
		
			
				
					|  |  |  | 	ret.Xid = ne.Xid | 
			
		
	
		
			
				
					|  |  |  | 	ret.Name = ne.Name | 
			
		
	
		
			
				
					|  |  |  | 	c.JSON(200, ret) | 
			
		
	
		
			
				
					|  |  |  | } |