Skip to content

Commit

Permalink
Add email/password authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
xendk committed Sep 25, 2024
1 parent c55d43b commit d2e5fcd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Intended Effort Versioning](https://jacobtomlinson.

## 1.3.2 - [Unreleased]

### Added
- Email/password authentication for legacy endpoint.

### Fixed
- Handle PHPs old BCrypt version.

Expand Down
12 changes: 12 additions & 0 deletions src/controllers/legacy_entity_controller.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class LegacyEntityController < Amber::Controller::Base

def index
token_user = nil : User?

# Legacy "token" authentication.
if params[:token]?
# Timelord uses a version of bcrypt hash that's basically only
# used by PHP, so we "fix" it to the version Crystal BCrypt
Expand Down Expand Up @@ -33,6 +35,16 @@ class LegacyEntityController < Amber::Controller::Base
end
end

# Temporary email/password authentication.
if params[:password]? && params[:email]?
token_user = User.find_by!(email: params[:email])
unless token_user.authenticate(params[:password])
halt!(403, "Forbidden")

return
end
end

location = Time::Location.load("Europe/Copenhagen")
date_from = Time.local(location).at_beginning_of_month
date_to = Time.local(location).at_end_of_day.shift(days: -1)
Expand Down

0 comments on commit d2e5fcd

Please sign in to comment.