示例#1
0
文件: user.go 项目: oblank/forum
func (r *resourceUser) Create(u *models.User) error {
	if u.Password == "" {
		return apiErrors.ThrowError(apiErrors.UserPasswordRequired)
	}
	u.Password = r.HashPassword(u.Password)
	u.Id = bson.NewObjectId()
	u.Role = models.NormalUser
	if err := collection(userColName).Insert(u); err != nil {
		if mgo.IsDup(err) {
			return apiErrors.ThrowError(apiErrors.UserExist)
		}
		panic(err)
	}

	return nil
}