added user model
This commit is contained in:
@@ -1,16 +1,16 @@
|
|||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
gem 'bcrypt', '~> 3.1.7'
|
||||||
|
|
||||||
platform :jruby do
|
platform :jruby do
|
||||||
gem 'activerecord-jdbcpostgresql-adapter'
|
gem 'activerecord-jdbcpostgresql-adapter'
|
||||||
gem 'jruby-openssl'
|
gem 'jruby-openssl'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
platform :ruby do
|
platform :ruby do
|
||||||
gem 'pg'
|
gem 'pg'
|
||||||
|
|
||||||
gem "activerecord"
|
gem "activerecord"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ GEM
|
|||||||
tzinfo (~> 1.1)
|
tzinfo (~> 1.1)
|
||||||
arel (6.0.0)
|
arel (6.0.0)
|
||||||
backports (3.6.4)
|
backports (3.6.4)
|
||||||
|
bcrypt (3.1.10)
|
||||||
|
bcrypt (3.1.10-java)
|
||||||
builder (3.2.2)
|
builder (3.2.2)
|
||||||
i18n (0.7.0)
|
i18n (0.7.0)
|
||||||
jdbc-postgres (9.3.1102)
|
jdbc-postgres (9.3.1102)
|
||||||
@@ -66,6 +68,7 @@ PLATFORMS
|
|||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
activerecord
|
activerecord
|
||||||
activerecord-jdbcpostgresql-adapter
|
activerecord-jdbcpostgresql-adapter
|
||||||
|
bcrypt (~> 3.1.7)
|
||||||
jruby-openssl
|
jruby-openssl
|
||||||
json
|
json
|
||||||
pg
|
pg
|
||||||
|
|||||||
20
front-api/controllers/user.rb
Normal file
20
front-api/controllers/user.rb
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
get '/user/auth' do
|
||||||
|
# TODO: do something that makes sense here
|
||||||
|
res = User.find_by(id: 1).try(:authenticate, 'spassword') # => false
|
||||||
|
res.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/user' do
|
||||||
|
request.body.rewind
|
||||||
|
json = request.body.read
|
||||||
|
|
||||||
|
user = User.new()
|
||||||
|
user.from_json(json, false)
|
||||||
|
|
||||||
|
if user.save
|
||||||
|
"ok"
|
||||||
|
else
|
||||||
|
status 400
|
||||||
|
user.errors.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
10
front-api/db/migrate/20150218053655_create_users.rb
Normal file
10
front-api/db/migrate/20150218053655_create_users.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class CreateUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :users do |t|
|
||||||
|
t.string :first_name
|
||||||
|
t.string :last_name
|
||||||
|
t.string :email
|
||||||
|
t.string :password_digest
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150207120207) do
|
ActiveRecord::Schema.define(version: 20150218053655) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -86,10 +86,8 @@ ActiveRecord::Schema.define(version: 20150207120207) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
create_table "sub_categories", force: :cascade do |t|
|
create_table "sub_categories", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "category_id"
|
t.integer "category_id"
|
||||||
t.datetime "created_at", null: false
|
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "units", force: :cascade do |t|
|
create_table "units", force: :cascade do |t|
|
||||||
@@ -99,4 +97,11 @@ ActiveRecord::Schema.define(version: 20150207120207) do
|
|||||||
t.string "number_of_pieces_suffix"
|
t.string "number_of_pieces_suffix"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "users", force: :cascade do |t|
|
||||||
|
t.string "first_name"
|
||||||
|
t.string "last_name"
|
||||||
|
t.string "email"
|
||||||
|
t.string "password_digest"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
9
front-api/models/user.rb
Normal file
9
front-api/models/user.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class User < ActiveRecord::Base
|
||||||
|
has_secure_password
|
||||||
|
validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation
|
||||||
|
|
||||||
|
validates :email, :uniqueness => {:case_sensitive => false, :message => "Email already exists!"},
|
||||||
|
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: "invalid email" }
|
||||||
|
|
||||||
|
validates :password, confirmation: true, length: { in:6..20, too_short: 'password needs to be at least 6 characters long' }
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user