Skip to content

Commit 8c8b1a6

Browse files
committed
Resolve linter errors
1 parent 73119bc commit 8c8b1a6

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ gem "redcarpet"
5858

5959
gem "devise"
6060

61-
gem 'jwt'
61+
gem "jwt"
6262

6363
group :development do
6464
# Access an IRB console on exceptions page and /console in development

app/controllers/api/authentication_controller.rb

+14-14
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,40 @@ def create
88
if user&.valid_password?(params[:password])
99
begin
1010
token = user.generate_jwt
11-
render json: {
12-
message: 'Login successful',
13-
token: token
11+
render json: {
12+
message: "Login successful",
13+
token: token
1414
}, status: :ok
1515
rescue JWT::EncodeError
16-
render json: { error: 'Authentication failed' }, status: :internal_server_error
16+
render json: { error: "Authentication failed" }, status: :internal_server_error
1717
end
1818
else
19-
render json: { error: 'Invalid credentials' }, status: :unauthorized
19+
render json: { error: "Invalid credentials" }, status: :unauthorized
2020
end
2121
end
2222

2323
def signup
24-
return render json: { error: 'Invalid email format' }, status: :unprocessable_entity unless
24+
return render json: { error: "Invalid email format" }, status: :unprocessable_entity unless
2525
params.dig(:user, :email)&.match?(URI::MailTo::EMAIL_REGEXP)
2626

27-
return render json: { error: 'Password must be at least 6 characters' }, status: :unprocessable_entity if
27+
return render json: { error: "Password must be at least 6 characters" }, status: :unprocessable_entity if
2828
params.dig(:user, :password)&.length.to_i < 6
2929

3030
user = User.new(user_params)
31-
31+
3232
if user.save
3333
begin
3434
token = user.generate_jwt
35-
render json: {
36-
message: 'Signup successful',
37-
token: token
35+
render json: {
36+
message: "Signup successful",
37+
token: token
3838
}, status: :created
3939
rescue JWT::EncodeError
40-
render json: { error: 'Failed to generate authentication token' }, status: :internal_server_error
40+
render json: { error: "Failed to generate authentication token" }, status: :internal_server_error
4141
end
4242
else
43-
render json: {
44-
errors: user.errors.full_messages
43+
render json: {
44+
errors: user.errors.full_messages
4545
}, status: :unprocessable_entity
4646
end
4747
end

app/models/user.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
# frozen_string_literal: true
2+
13
class User < ApplicationRecord
24
devise :database_authenticatable, :registerable,
35
:recoverable, :rememberable, :validatable
4-
56
def generate_jwt
67
JWT.encode(
7-
{
8-
id: id,
9-
exp: 60.days.from_now.to_i
10-
},
8+
{
9+
id: id,
10+
exp: 60.days.from_now.to_i
11+
},
1112
Rails.application.credentials.secret_key_base
1213
)
1314
end

config/initializers/devise.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
# confirmation, reset password and unlock tokens in the database.
1515
# Devise will use the `secret_key_base` as its `secret_key`
1616
# by default. You can change it below and use your own secret key.
17-
# config.secret_key = 'f5c3627ab84eb5a12eab9feae096d10ac001e2a3980e87567922107429a516f3939c17512beb6c2b57330814611d42511d91d603a058391729519332b0a3e826'
17+
# config.secret_key =
18+
# 'f5c3627ab84eb5a12eab9feae096d10ac001e2a3980e87567922107429a516f39
19+
# 39c17512beb6c2b57330814611d42511d91d603a058391729519332b0a3e826'
1820

1921
# ==> Controller configuration
2022
# Configure the parent class to the devise controllers.
@@ -24,7 +26,7 @@
2426
# Configure the e-mail address which will be shown in Devise::Mailer,
2527
# note that it will be overwritten if you use your own mailer class
2628
# with default "from" parameter.
27-
config.mailer_sender = '[email protected]'
29+
config.mailer_sender = "[email protected]"
2830

2931
# Configure the class responsible to send e-mails.
3032
# config.mailer = 'Devise::Mailer'
@@ -36,7 +38,7 @@
3638
# Load and configure the ORM. Supports :active_record (default) and
3739
# :mongoid (bson_ext recommended) by default. Other ORMs may be
3840
# available as additional gems.
39-
require 'devise/orm/active_record'
41+
require "devise/orm/active_record"
4042

4143
# ==> Configuration for any authentication mechanism
4244
# Configure which keys are used when authenticating a user. The default is
@@ -126,7 +128,9 @@
126128
config.stretches = Rails.env.test? ? 1 : 12
127129

128130
# Set up a pepper to generate the hashed password.
129-
# config.pepper = '8f277f0b4e8090a67c44746c589cd5edfaab345bf9a650db74a63b38cc431b1710fcf704021b401c88db3bcd98e29a71b4eecf62bec170b138442818a3d33013'
131+
# config.pepper =
132+
# '8f277f0b4e8090a67c44746c589cd5edfaab345bf9a650db74a63b38cc431b1710fcf704021b
133+
# 401c88db3bcd98e29a71b4eecf62bec170b138442818a3d33013'
130134

131135
# Send a notification to the original email when the user's email is changed.
132136
# config.send_email_changed_notification = false

config/routes.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
66

77
# Serve websocket cable requests in-process
8-
# mount ActionCable.server => '/cable'
8+
# mount ActionCable.server => "/cable"
99

1010
root "pages#index"
1111

1212
namespace :api do
13-
post 'signup', to: 'authentication#signup'
14-
post 'login', to: 'authentication#create'
13+
post "signup", to: "authentication#signup"
14+
post "login", to: "authentication#create"
1515
end
1616

1717
get "simple", to: "pages#simple"

test/factories/users.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
# frozen_string_literal: true
2+
13
FactoryBot.define do
2-
factory :user do
3-
4-
end
4+
# factory :user do
5+
# end
56
end

test/models/user_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require "test_helper"
24

35
class UserTest < ActiveSupport::TestCase

0 commit comments

Comments
 (0)