Example #1
0
func (a *SignApi) Regist(args util.MapData) (bool, error) {
	appConf := gos.Configuration.GetConf("other")
	if appConf.Get("allow_regist") == "1" {
		err := auth.Regist(args.GetString("cipher"))
		return err == nil, err
	}

	return false, fmt.Errorf("管理员已经关闭了用户注册")
}
Example #2
0
func (a *SignApi) UserLogin(args util.MapData) (bool, error) {
	au := a.GetUserAuth().(*auth.UserAuth)

	err := au.Login(args.GetString("cipher"))
	if err != nil {
		return false, err
	}

	au.SetCookie(30 * 24 * 3600)

	return true, err
}
Example #3
0
func (a *PublicApi) IsExists(args util.MapData) (int, error) {
	table := "users"
	field := args.GetString("field")
	val := args.GetString("value")

	exists := db.NewExistsBuilder(table).Where(field+"=?", val)

	if isEx := exists.Exists(); isEx {
		return 1, nil
	} else {
		return 0, nil
	}
}
Example #4
0
func (s *SignApi) ChangePassword(args util.MapData) (bool, error) {
	old := args.GetString("old")
	cipher := args.GetString("cipher")

	err := s.GetUserAuth().CheckCipher(old)
	if err != nil {
		return false, fmt.Errorf("登录名和原始密码不匹配,请确认后重新输入")
	}

	err = auth.ChangePassword(s.GetUserAuth().UserID(), cipher)
	if err != nil {
		return false, err
	}

	err = s.GetUserAuth().ChangeStatus(s.GetUserAuth().UserID(), 1)
	if err != nil {
		return false, err
	}

	return true, nil
}
Example #5
0
func (a *ArticleApi) List(args util.MapData) (db.DataSet, error) {
	nick := args.GetString("nick")
	page := args.GetInt("page")

	q := db.NewQueryBuilder("articles").
		Page(page, 20).
		Order("id desc").
		Select("cid,title,description,status,created_at")

	if nick != "" {
		u, err := user.NewUserModel().GetByNickAllField(nick)
		if err != nil {
			return nil, err
		}
		if u.Empty() {
			return nil, gos.DoError("没有找到相应的记录", nick)
		}
		q.Where("user_id=?", u.GetInt64("id"))
	}

	ds, err := q.Query()
	return ds.Bytes2String(), err
}
Example #6
0
func (a *WriterApi) Save(args util.MapData) (string, error) {
	cid := args.GetString("cid")
	title := args.GetString("title")
	body := args.GetBytes("body")
	images := args.GetStringSlice("images")
	au := a.GetUserAuth()

	var err error

	model := article.NewArticleModel()
	if cid == "" {
		cid, err = model.New(au.UserID(), title, body)
	} else {
		_, err = model.Update(cid, title, body)
	}
	if err != nil {
		return cid, err
	}

	article, _ := db.NewQueryBuilder(model.Table()).Select("id").Where("cid=?", cid).QueryOne()
	if article.Empty() {
		return cid, gos.DoError("没有找到相应的记录")
	}

	count := len(images)
	if count > 0 {
		image := db.DataRow{}
		image["article_id"] = article.GetInt64("id")
		for i := 0; i < count; i++ {
			images[i] = fmt.Sprint("'", images[i], "'")
		}
		db.NewUpdateBuilder("images").
			Where(fmt.Sprint("name in (", strings.Join(images, ","), ")")).
			Update(image)
	}

	return cid, nil
}