Created
December 25, 2014 21:54
-
-
Save joepie91/cc0a7f4c1f4e6974d903 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise = require "bluebird" | |
appUtil = require "../util" | |
module.exports = (shelf) -> | |
shelf.model "User", | |
tableName: "users" | |
hasTimestamps: true | |
projects: -> @hasMany "Project", "owner_id" | |
enable: -> | |
if @get "activated" | |
throw new util.errors.RequirementsError("The user is already enabled.") | |
else | |
@set "activated", true | |
@saveChanges() | |
disable: -> | |
if not @get "activated" | |
throw new util.errors.RequirementsError("The user is already disabled.") | |
else | |
@set "activated", false | |
@saveChanges() | |
verifyPassword: (password) -> | |
return appUtil.verifyHash @get("hash"), password | |
setPassword: (password) -> | |
Promise.try -> | |
appUtil.hash password | |
.then (hash) => | |
@set "hash", hash | |
@saveChanges() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment