-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
383 changed files
with
12,153 additions
and
1,636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
class EmailConfirmationsController < ApplicationController | ||
skip_before_action :authenticate_user! | ||
skip_after_action :verify_authorized | ||
before_action :verify_confirmed_user | ||
|
||
def show | ||
resend_url = resend_email_confirmation_path({ email: user.email }) | ||
render :show, locals: { user:, resend_url: } | ||
end | ||
|
||
def resend | ||
user.send_confirmation_instructions | ||
flash[:notice] = t("confirmation.send_instructions", email: user.email) | ||
redirect_to new_user_session_path | ||
end | ||
|
||
private | ||
|
||
def verify_confirmed_user | ||
if user.confirmed? | ||
redirect_to root_path | ||
end | ||
end | ||
|
||
def user | ||
@_user ||= User.kept.find_by_email!(params[:email]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
class InternalApi::V1::ProfileController < InternalApi::V1::ApplicationController | ||
def show | ||
authorize :index, policy_class: ProfilePolicy | ||
if current_user.avatar.attached? | ||
avatar_url = url_for(current_user.avatar) | ||
end | ||
render json: { user: current_user.as_json.merge("avatar_url" => avatar_url) }, status: :ok | ||
end | ||
|
||
def remove_avatar | ||
authorize :remove_avatar, policy_class: ProfilePolicy | ||
current_user.avatar.destroy | ||
render json: { notice: "Avatar deleted successfully" }, status: :ok | ||
end | ||
|
||
def update | ||
authorize :update, policy_class: ProfilePolicy | ||
if params[:user][:current_password].blank? | ||
current_user.update_without_password(user_params.except(:current_password)) | ||
render json: { notice: "User updated" }, status: :ok | ||
elsif validate_current_password && validate_password_length && validate_password_confirmation | ||
current_user.update_with_password(user_params) | ||
render json: { notice: "Password updated" }, status: :ok | ||
else | ||
render json: { error: "Something went wrong" }, status: :unprocessable_entity | ||
end | ||
rescue Exception => e | ||
render json: { error: e.message }, status: :unprocessable_entity | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit( | ||
:first_name, :last_name, :current_password, :password, :password_confirmation, :avatar | ||
) | ||
end | ||
|
||
def validate_current_password | ||
return true if current_user.valid_password?(params[:user][:current_password]) | ||
|
||
raise Exception.new("Current password is not correct") | ||
end | ||
|
||
def validate_password_confirmation | ||
return true if params[:user][:password] == params[:user][:password_confirmation] | ||
|
||
raise Exception.new("Password and password confirmation does not match") | ||
end | ||
|
||
def validate_password_length | ||
return true if params[:user][:password].present? && | ||
params[:user][:password].length > 5 && | ||
params[:user][:password_confirmation].length > 5 | ||
|
||
raise Exception.new("Password and password confirmation should be of minimum 6 characters") | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
app/controllers/internal_api/v1/profiles/bank_account_details_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
|
||
class InternalApi::V1::Profiles::BankAccountDetailsController < InternalApi::V1::ApplicationController | ||
before_action :load_wise_account, only: [:index] | ||
before_action :fetch_wise_account, only: [:update] | ||
|
||
def index | ||
authorize :index, policy_class: Profiles::BillingPolicy | ||
render :index, locals: { | ||
wise_account: @wise_account | ||
} | ||
end | ||
|
||
def create | ||
authorize :create, policy_class: Profiles::BillingPolicy | ||
|
||
@wise_account = WiseAccount.create!( | ||
recipient_id: params[:id], | ||
profile_id: params[:profile], | ||
target_currency: params[:currency], | ||
source_currency: "USD", | ||
company_id: current_company.id, | ||
user_id: current_user.id | ||
) | ||
|
||
render :index, locals: { | ||
wise_account: @wise_account | ||
} | ||
rescue => error | ||
render json: { | ||
error: error.message | ||
}, status: 500 | ||
end | ||
|
||
def update | ||
authorize :update, policy_class: Profiles::BillingPolicy | ||
|
||
@account.update!( | ||
recipient_id: params[:id], | ||
profile_id: params[:profile], | ||
target_currency: params[:currency], | ||
source_currency: "USD", | ||
company_id: current_company.id, | ||
user_id: current_user.id | ||
) | ||
|
||
render :index, locals: { | ||
wise_account: @account | ||
} | ||
rescue => error | ||
render json: { | ||
error: error.message | ||
}, status: 500 | ||
end | ||
|
||
private | ||
|
||
def load_wise_account | ||
@wise_account ||= current_user.wise_account | ||
end | ||
|
||
def fetch_wise_account | ||
@account = WiseAccount.find(params[:account_id]) | ||
end | ||
end |
Oops, something went wrong.