User contact activation done.
parent
d5f2b3816f
commit
8ddf5cf316
17
src/authd.cr
17
src/authd.cr
|
@ -70,10 +70,9 @@ class AuthD::Response
|
||||||
end
|
end
|
||||||
|
|
||||||
class UserValidated < Response
|
class UserValidated < Response
|
||||||
property uid : Int32
|
property user : ::AuthD::User::Public
|
||||||
property email : String
|
|
||||||
|
|
||||||
initialize :uid, :email
|
initialize :user
|
||||||
end
|
end
|
||||||
|
|
||||||
class UsersList < Response
|
class UsersList < Response
|
||||||
|
@ -199,10 +198,10 @@ class AuthD::Request
|
||||||
# to validate users.
|
# to validate users.
|
||||||
property shared_key : String
|
property shared_key : String
|
||||||
|
|
||||||
property email : String
|
property login : String
|
||||||
property activation_key : String
|
property activation_key : String
|
||||||
|
|
||||||
initialize :shared_key, :email, :activation_key
|
initialize :shared_key, :login, :activation_key
|
||||||
end
|
end
|
||||||
|
|
||||||
class GetUser < Request
|
class GetUser < Request
|
||||||
|
@ -382,7 +381,7 @@ module AuthD
|
||||||
phone : String?,
|
phone : String?,
|
||||||
profile : JSON::Any?) : ::AuthD::User::Public | Exception
|
profile : JSON::Any?) : ::AuthD::User::Public | Exception
|
||||||
|
|
||||||
send Request::ValidateUser.new @key, login, password, email, phone, profile
|
send Request::AddUser.new @key, login, password, email, phone, profile
|
||||||
|
|
||||||
response = Response.from_ipc read
|
response = Response.from_ipc read
|
||||||
|
|
||||||
|
@ -398,9 +397,11 @@ module AuthD
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_user(email : String, activation_key : String) : ::AuthD::User::Public | Exception
|
def validate_user(login : String, activation_key : String) : ::AuthD::User::Public | Exception
|
||||||
|
|
||||||
send Request::AddUser.new @key, email, activation_key
|
pp! login
|
||||||
|
pp! activation_key
|
||||||
|
send Request::ValidateUser.new @key, login, activation_key
|
||||||
|
|
||||||
response = Response.from_ipc read
|
response = Response.from_ipc read
|
||||||
|
|
||||||
|
|
23
src/main.cr
23
src/main.cr
|
@ -82,6 +82,8 @@ class AuthD::Service
|
||||||
user.contact.email = request.email
|
user.contact.email = request.email
|
||||||
user.contact.phone = request.phone unless request.phone.nil?
|
user.contact.phone = request.phone unless request.phone.nil?
|
||||||
|
|
||||||
|
pp! user
|
||||||
|
|
||||||
request.profile.try do |profile|
|
request.profile.try do |profile|
|
||||||
user.profile = profile
|
user.profile = profile
|
||||||
end
|
end
|
||||||
|
@ -89,6 +91,27 @@ class AuthD::Service
|
||||||
@users << user
|
@users << user
|
||||||
|
|
||||||
Response::UserAdded.new user.to_public
|
Response::UserAdded.new user.to_public
|
||||||
|
when Request::ValidateUser
|
||||||
|
if request.shared_key != @jwt_key
|
||||||
|
return Response::Error.new "invalid authentication key"
|
||||||
|
end
|
||||||
|
|
||||||
|
user = @users_per_login.get? request.login
|
||||||
|
|
||||||
|
if user.nil?
|
||||||
|
return Response::Error.new "user not found"
|
||||||
|
end
|
||||||
|
|
||||||
|
# remove the user contact activation key: the email is validated
|
||||||
|
if user.contact.activation_key == request.activation_key
|
||||||
|
user.contact.activation_key = nil
|
||||||
|
else
|
||||||
|
return Response::Error.new "Wrong activation key"
|
||||||
|
end
|
||||||
|
|
||||||
|
@users_per_uid.update user.uid.to_s, user
|
||||||
|
|
||||||
|
Response::UserValidated.new user.to_public
|
||||||
when Request::GetUserByCredentials
|
when Request::GetUserByCredentials
|
||||||
user = @users_per_login.get? request.login
|
user = @users_per_login.get? request.login
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
require "json"
|
require "json"
|
||||||
|
|
||||||
|
require "uuid"
|
||||||
|
|
||||||
require "./token.cr"
|
require "./token.cr"
|
||||||
|
|
||||||
class AuthD::User
|
class AuthD::User
|
||||||
|
@ -19,10 +21,13 @@ class AuthD::User
|
||||||
class Contact
|
class Contact
|
||||||
include JSON::Serializable
|
include JSON::Serializable
|
||||||
|
|
||||||
property email : String?
|
# the activation key is removed once the user is validated
|
||||||
property phone : String?
|
property activation_key : String?
|
||||||
|
property email : String?
|
||||||
|
property phone : String?
|
||||||
|
|
||||||
def initialize(@email = nil, @phone = nil)
|
def initialize(@email = nil, @phone = nil)
|
||||||
|
@activation_key = UUID.random.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue