示例#1
0
//获取一个文章
func (this *Articles) GetEx(id int64) (*Articles, error) {
	defer db.Close()
	m := new(Articles)

	condition := qbs.NewEqualCondition("id", id)
	err := db.Condition(condition).Find(m)
	return m, err
}
示例#2
0
//分页获取账户
func (this *Users) GetAll() (us []*Users, err error) {
	defer db.Close()

	condition := qbs.NewEqualCondition("Deleted", utils.DelNormal)
	err = db.Condition(condition).OmitFields("Password", "Updator", "Ip").FindAll(&us)

	return
}
示例#3
0
//获取一个可用文章,屏蔽禁用或已删除的文章
func (this *Articles) Get(id int64) (*Articles, error) {
	defer db.Close()
	m := new(Articles)

	condition := qbs.NewEqualCondition("deleted", utils.DelNormal).AndEqual("id", id)
	err := db.Condition(condition).Find(m)
	return m, err
}
示例#4
0
func (this *Channels) GetByName(enname string) (*Channels, error) {
	defer db.Close()
	m := new(Channels)

	condition := qbs.NewEqualCondition("Deleted", utils.DelNormal).AndEqual("enname", enname)
	err := db.Condition(condition).Find(m)
	return m, err
}
示例#5
0
//获取一个账户
func (this *Users) GetEx(id int64) (*Users, error) {
	defer db.Close()
	m := new(Users)
	//err := db.WhereEqual("id", id).Find(m)
	condition := qbs.NewEqualCondition("id", id)
	err := db.Condition(condition).Find(m)
	return m, err
}
示例#6
0
//获取一个可用图片,屏蔽禁用或已删除的图片
func (this *Images) Get(id int64) (*Images, error) {
	defer db.Close()
	m := new(Images)

	condition := qbs.NewEqualCondition("deleted", 0).AndEqual("id", id)
	err := db.Condition(condition).Find(m)
	return m, err
}
示例#7
0
//分页获取图片
func (this *Images) GetImages(args ...interface{}) (us []*Images, err error) {
	defer db.Close()

	condition := qbs.NewEqualCondition("Deleted", utils.DelNormal).AndEqual("Status", utils.StatEnabled)

	if len(args) > 0 && args[0].(int64) > 0 {
		condition = condition.AndEqual("articleid", args[0].(int64))
	}

	err = db.Condition(condition).OmitFields("Created", "Creator", "Updated", "Updator", "Ip").OrderByDesc("sequence").FindAll(&us)
	return
}
示例#8
0
//分页获取文章
func (this *Articles) GetArticles(channelid int64, page *Pagination) (us []*Articles, err error) {
	defer db.Close()

	condition := qbs.NewEqualCondition("Deleted", utils.DelNormal).AndEqual("Status", utils.StatEnabled)
	//文章频道
	if channelid > 0 {
		condition = condition.AndEqual("channelid", channelid)
	}
	//符合条件的记录数
	page.Count = int(db.Condition(condition).Count("articles"))

	err = db.Condition(condition).Limit(int(page.Size)).Offset(int((page.Index-1)*page.Size)).
		OmitFields("Keywords", "Description", "Author", "Intro", "Content", "Created", "Creator", "Updated", "Updator", "Ip").
		OrderByDesc("sequence").OrderByDesc("Updated").FindAll(&us)
	return
}
示例#9
0
//登录
func (this *Users) Login(loginName, password string, f *Field) (*Users, error) {
	defer db.Close()

	u := new(Users)
	condition := qbs.NewEqualCondition("Loginname", loginName).AndEqual("Deleted", utils.DelNormal)
	err := db.Condition(condition).Find(u)

	if err != nil {
		return nil, errors.New("accoundNotFound")
	} else {
		//是否被锁定
		if u.Status == utils.StatDisabled {
			return nil, errors.New("accountLocked")
		}
		//校验密码
		if u.Password == utils.MD5(password) {
			//db.Save(u)
			return u, nil
		} else {
			return nil, errors.New("invalidPassword")
		}
	}

}
示例#10
0
/*
是否存在同名账户
*/
func (this *Users) Exist(name string) bool {
	defer db.Close()
	condition := qbs.NewEqualCondition("loginname", name)
	num := db.Condition(condition).Count("users")
	return num > 0
}