app/volt/models/user.rb in volt-0.8.21 vs app/volt/models/user.rb in volt-0.8.22.beta1
- old
+ new
@@ -1,38 +1,33 @@
if RUBY_PLATFORM != 'opal'
require 'bcrypt'
end
-class User < Volt::Model
- validate :username, unique: true, length: 8
- if RUBY_PLATFORM == 'opal'
- # Don't validate on the server
- validate :password, length: 8
- end
-
- def password=(val)
- if Volt.server?
- # on the server, we bcrypt the password and store the result
- self._hashed_password = BCrypt::Password.create(val)
- else
- self._password = val
+module Volt
+ class User < Model
+ # returns true if the user configured using the username
+ def self.login_field
+ if Volt.config.public.try(:auth).try(:use_username)
+ :username
+ else
+ :email
+ end
end
- end
- # Login the user, return a promise for success
- def self.login(username, password)
- puts "Login now"
- UserTasks.login(username, password).then do |result|
- puts "Got: #{result.inspect}"
+ validate login_field, unique: true, length: 8
- # Assign the user_id cookie for the user
- $page.cookies._user_id = result
+ if RUBY_PLATFORM == 'opal'
+ # Don't validate on the server
+ validate :password, length: 8
+ end
- # Pass nil back
- nil
+ def password=(val)
+ if Volt.server?
+ # on the server, we bcrypt the password and store the result
+ self._hashed_password = BCrypt::Password.create(val)
+ else
+ self._password = val
+ end
end
- end
- def self.logout
- $page.cookies.delete(:user_id)
end
end