Ejemplo n.º 1
0
// update user password with user id and new password
func UpdatePassword(id int64, newPassword string) error {
	u := new(User)
	u.Salt = utils.Md5String(newPassword)[8:24]
	u.Password = utils.Sha256String(newPassword + u.Salt)
	if _, err := vars.Db.Cols("password,salt").Where("id = ?", id).Update(u); err != nil {
		log.Error("Db|UpdatePassword|%d|%s", id, err.Error())
		return err
	}
	return nil
}
Ejemplo n.º 2
0
// new site init data
func NewSiteInitData(engine *xorm.Engine) {
	// default user
	user := &model.User{
		Name:      "admin",
		Nick:      "admin",
		Email:     "*****@*****.**",
		Url:       "#",
		AvatarUrl: utils.GravatarLink("*****@*****.**"),
		Profile:   "this is an administrator",
		Role:      model.USER_ROLE_ADMIN,
		Status:    model.USER_STATUS_ACTIVE,
	}
	user.Salt = utils.Md5String("123456789")[8:24]
	user.Password = utils.Sha256String("123456789" + user.Salt)
	if _, err := engine.Insert(user); err != nil {
		log.Error("NewSite | %s", err.Error())
		return
	}

	// default article
	article := &model.Article{
		Title:         "Welcome to Purine",
		Link:          "welcome-to-purine",
		Preview:       blogPreview,
		Body:          blogContent,
		TagString:     "blog",
		Hits:          1,
		Comments:      0,
		Status:        model.ARTICLE_STATUS_PUBLISH,
		CommentStatus: model.ARTICLE_COMMENT_OPEN,
		AuthorId:      user.Id,
	}
	if _, err := engine.Insert(article); err != nil {
		log.Error("NewSite | %s", err.Error())
		return
	}

	// default settings
	settings := make([]interface{}, 0)
	settings = append(settings, &model.Setting{"title", "Purine", 0})
	settings = append(settings, &model.Setting{"subtitle", "a simple blog engine", 0})
	settings = append(settings, &model.Setting{"desc", "a simple blog engine by golang", 0})
	settings = append(settings, &model.Setting{"keyword", "purine,blog,golang", 0})
	settings = append(settings, &model.Setting{"theme", "default", 0})
	settings = append(settings, &model.Setting{"baseurl", "http://localhost:9999/", 0})
	settings = append(settings, &model.Setting{"media_imageext", ".jpg,.jpeg,.png,.gif", 0})
	settings = append(settings, &model.Setting{"media_fileext", ".txt,.zip,.doc,.xls,.ppt,.pdf", 0})
	settings = append(settings, &model.Setting{"media_nameformat", ":hash", 0})
	settings = append(settings, &model.Setting{"media_maxsize", strconv.Itoa(2 * 1024 * 1024), 0})
	if _, err := engine.Insert(settings...); err != nil {
		log.Error("NewSite | %s", err.Error())
		return
	}
}
Ejemplo n.º 3
0
// check user's password
func (u *User) CheckPassword(pwd string) bool {
	return u.Password == utils.Sha256String(pwd+u.Salt)
}