1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Initial commit

This commit is contained in:
Josh Pigford 2024-02-02 09:05:04 -06:00
commit 99de24ac70
147 changed files with 3519 additions and 0 deletions

View file

@ -0,0 +1,10 @@
class AccountsController < ApplicationController
def index
end
def new
end
def show
end
end

View file

@ -0,0 +1,35 @@
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
private
def authenticate_user!
redirect_to new_session_path unless user_signed_in?
end
def current_user
Current.user || authenticate_user_from_session
end
helper_method :current_user
def authenticate_user_from_session
User.find_by(id: session[:user_id])
end
def user_signed_in?
current_user.present?
end
helper_method :user_signed_in?
def login(user)
Current.user = user
reset_session
session[:user_id] = user.id
end
def logout
Current.user = nil
reset_session
end
end

View file

View file

@ -0,0 +1,6 @@
class PagesController < ApplicationController
before_action :authenticate_user!
def dashboard
end
end

View file

@ -0,0 +1,40 @@
class PasswordResetsController < ApplicationController
layout "auth"
def new
end
def create
if (user = User.find_by(email: params[:email]))
PasswordMailer.with(
user: user,
token: user.generate_token_for(:password_reset)
).password_reset.deliver_later
end
redirect_to root_path, notice: "If an account with that email exists, we have sent a link to reset your password."
end
def edit
end
def update
if @user.update(password_params)
redirect_to new_session_path, notice: "Your password has been reset."
else
render :edit, status: :unprocessable_entity
end
end
private
def set_user_by_token
@user = User.find_by_token_for(password_reset: params[:token])
redirect_to new_password_reset_path, alert: "Invalid token." unless @user.present?
end
def password_params
params.require(:user).permit(:password, :password_confirmation)
end
end

View file

@ -0,0 +1,21 @@
class PasswordsController < ApplicationController
before_action :authenticate_user!
def edit
end
def update
if current_user.update(password_params)
redirect_to root_path, notice: "Your password has been updated successfully."
else
render :edit, status: :unprocessable_entity
end
end
private
def password_params
params.require(:user).permit(:password, :password_confirmation, :password_challenge).with_defaults(password_challenge: "")
end
end

View file

@ -0,0 +1,30 @@
class RegistrationsController < ApplicationController
layout "auth"
def new
@user = User.new
end
def create
@user = User.new(user_params)
family = Family.new
@user.family = family
if @user.save
login @user
flash[:notice] = "You have signed up successfully."
redirect_to root_path
else
flash[:alert] = "Invalid input, please try again."
render :new
end
end
private
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
end

View file

@ -0,0 +1,22 @@
class SessionsController < ApplicationController
layout "auth"
def new
end
def create
if user = User.authenticate_by(email: params[:email], password: params[:password])
login user
redirect_to root_path
else
flash.now[:alert] = "Invalid email or password."
render :new, status: :unprocessable_entity
end
end
def destroy
logout
redirect_to root_path, notice: "You have signed out successfully."
end
end