Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rails_api_authentication
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
rails_api_authentication
Commits
b63b8f89
Commit
b63b8f89
authored
Jul 05, 2017
by
liyijie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'lan/update_register' into 'master'
Update register to make it can accept more attrs See merge request
!1
parents
9980927d
cd30aecd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
auth_session.rb
lib/rails_api_authentication/auth_session.rb
+2
-2
authable.rb
lib/rails_api_authentication/authable.rb
+10
-2
No files found.
lib/rails_api_authentication/auth_session.rb
View file @
b63b8f89
...
@@ -11,12 +11,12 @@ module RailsApiAuthentication
...
@@ -11,12 +11,12 @@ module RailsApiAuthentication
@auth_token
=
self
.
class
.
klass
.
login
(
session_params
[
auth_key
],
session_params
[
auth_password
])
@auth_token
=
self
.
class
.
klass
.
login
(
session_params
[
auth_key
],
session_params
[
auth_password
])
render
json:
{
token:
@auth_token
.
token
},
status:
200
render
json:
{
token:
@auth_token
.
token
},
status:
200
rescue
UserError
=>
e
rescue
UserError
=>
e
render
json:
e
.
message
,
status:
e
.
status
render
json:
{
error:
e
.
message
}
,
status:
e
.
status
end
end
def
destroy
def
destroy
self
.
send
(
"current_
#{
self
.
class
.
klass_sym
}
"
)
&
.
logout
self
.
send
(
"current_
#{
self
.
class
.
klass_sym
}
"
)
&
.
logout
render
json:
"logout successful"
,
status:
200
render
json:
{
message:
"logout successful"
}
,
status:
200
end
end
private
private
...
...
lib/rails_api_authentication/authable.rb
View file @
b63b8f89
...
@@ -35,13 +35,20 @@ module RailsApiAuthentication
...
@@ -35,13 +35,20 @@ module RailsApiAuthentication
user
.
nil?
?
raise
(
UserError
.
new
(
401
,
'-1'
,
'Unauthorized'
))
:
user
user
.
nil?
?
raise
(
UserError
.
new
(
401
,
'-1'
,
'Unauthorized'
))
:
user
end
end
def
register
(
name
,
password
)
def
register
(
name
,
password
,
attrs
=
{}
)
raise
(
UserError
.
new
(
401
,
'-1'
,
'password is blank'
))
if
password
.
blank?
raise
(
UserError
.
new
(
401
,
'-1'
,
'password is blank'
))
if
password
.
blank?
self
.
create!
(
@auth_key
=>
name
,
@auth_password
=>
generate_password
(
password
)
)
self
.
create!
(
{
@auth_key
=>
name
,
@auth_password
=>
generate_password
(
password
)}.
merge
attrs
)
rescue
ActiveRecord
::
RecordInvalid
=>
e
rescue
ActiveRecord
::
RecordInvalid
=>
e
raise
UserError
.
new
(
401
,
'-1'
,
e
.
message
)
raise
UserError
.
new
(
401
,
'-1'
,
e
.
message
)
end
end
def
register_with
(
attrs
=
{})
attrs
=
attrs
.
clone
name
=
attrs
.
delete
@auth_key
password
=
attrs
.
delete
@auth_password
register
(
name
,
password
,
attrs
)
end
private
private
def
salt
(
password
,
suffix
)
def
salt
(
password
,
suffix
)
...
@@ -78,3 +85,4 @@ module RailsApiAuthentication
...
@@ -78,3 +85,4 @@ module RailsApiAuthentication
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment