-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/action mailer #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
e75ba55
9ccfc71
64dd2ad
44eb68c
f0bf12e
ef36275
f745c27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| class Web::PasswordResetsController < Web::ApplicationController | ||
| def new; end | ||
|
|
||
| def create | ||
| @user = User.find_by(email: params.dig('user', 'email')) | ||
|
|
||
| if @user.present? | ||
| @token = @user.generate_token | ||
| UserMailer.with(user: @user, token: @token).reset_password.deliver_now | ||
| @user.update(reset_password_token_digest: @token) | ||
| end | ||
| redirect_to new_session_path | ||
| end | ||
|
|
||
| def edit | ||
| @user = GlobalID::Locator.locate_signed(params[:token], for: 'password_reset') | ||
| if @user.nil? | ||
| redirect_to new_session_path | ||
| elsif @user.reset_password_token_digest != params[:token] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Для валидации данных, поступающих в контроллер, используют формы There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| redirect_to new_session_path | ||
| end | ||
| end | ||
|
|
||
| def update | ||
| @user = GlobalID::Locator.locate_signed(params[:token], for: 'password_reset') | ||
| if @user.update(password_params.merge(reset_password_token_digest: nil)) | ||
| redirect_to new_session_path | ||
| else | ||
| render :edit | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def password_params | ||
| params.require(:user).permit(:password, :password_confirmation) | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| class UserMailer < ApplicationMailer | ||
| def task_created | ||
| user = params[:user] | ||
| @task = params[:task] | ||
|
|
||
| mail(from: 'noreply@taskmanager.com', to: user.email, subject: 'New Task Created') | ||
| end | ||
|
|
||
| def task_updated | ||
| @task = params[:task] | ||
| author = @task.author | ||
|
|
||
| mail(from: 'noreply@taskmanager.com', to: author.email, subject: 'Task Updated') | ||
| end | ||
|
|
||
| def task_deleted | ||
| @task = params[:task] | ||
| author = @task.author | ||
|
|
||
| mail(from: 'noreply@taskmanager.com', to: author.email, subject: 'Task Deleted') | ||
| end | ||
|
|
||
| def reset_password | ||
| @user = params[:user] | ||
| @token = params[:token] | ||
|
|
||
| mail(from: 'noreply@taskmanager.com', to: @user.email, subject: 'Password Reset') | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,8 @@ class User < ApplicationRecord | |
| validates :first_name, presence: true, length: { minimum: 2 } | ||
| validates :last_name, presence: true, length: { minimum: 2 } | ||
| validates :email, presence: true, uniqueness: true, format: { with: /\w*@{1}\w*/ } | ||
|
|
||
| def generate_token | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. метод не относится к модели. Нужно вынести в отдельный сервис |
||
| to_sgid(for: 'password_reset', expires_in: 1.day).to_s | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| html | ||
| body | ||
| = yield |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| = yield |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| tr | ||
| td bgcolor="#ffffff" style="padding: 10px 30px;" | ||
| p | ||
| | Dear user! | ||
| p | ||
| | We are honored to announce you that Task #{@task.id} was #{action}. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| tr | ||
| td | ||
| small | ||
| center style="color: #d3d3d3;" | ||
| | © Dualboot Learn 2023 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| tr | ||
| td bgcolor="#3F52B5" align="center" style="padding: 30px 0;" | ||
| span style="color:#ffffff; font-size: 20px; font-family:Arial, Helvetica, sans-serif;" | ||
| b | ||
| Task Board Project |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| doctype html | ||
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
| html lang="en" | ||
| head | ||
| meta http-equiv="Content-Type" content="text/html; charset=utf-8" | ||
| title="Email template" | ||
| body bgcolor="#efefef" style="padding: 0; margin: 0" | ||
| table border="0" cellpadding="0" cellspacing="0" width="100%" | ||
| tr | ||
| td align="center" | ||
| table width="600" border="0" cellpadding="30" cellspacing="0" | ||
| ==render 'header' | ||
| tr | ||
| td bgcolor="#ffffff" style="padding: 10px 30px;" | ||
| p | ||
| | Dear user! | ||
| p | ||
| = link_to 'Click this link, to reset your password', edit_password_resets_url(token: @token) | ||
| ==render 'footer' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| doctype html | ||
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
| html lang="en" | ||
| head | ||
| meta http-equiv="Content-Type" content="text/html; charset=utf-8" | ||
| title="Email template" | ||
| body bgcolor="#efefef" style="padding: 0; margin: 0" | ||
| table border="0" cellpadding="0" cellspacing="0" width="100%" | ||
| tr | ||
| td align="center" | ||
| table width="600" border="0" cellpadding="30" cellspacing="0" | ||
| ==render 'header' | ||
| ==render 'body', object: @task, action: 'created' | ||
| ==render 'footer' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| doctype html | ||
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
| html lang="en" | ||
| head | ||
| meta http-equiv="Content-Type" content="text/html; charset=utf-8" | ||
| title="Email template" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. кажется еще есть общие участки кода |
||
| body bgcolor="#efefef" style="padding: 0; margin: 0" | ||
| table border="0" cellpadding="0" cellspacing="0" width="100%" | ||
| tr | ||
| td align="center" | ||
| table width="600" border="0" cellpadding="30" cellspacing="0" | ||
| ==render 'header' | ||
| ==render 'body', object: @task, action: 'deleted' | ||
| ==render 'footer' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| doctype html | ||
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | ||
| html lang="en" | ||
| head | ||
| meta http-equiv="Content-Type" content="text/html; charset=utf-8" | ||
| title="Email template" | ||
| body bgcolor="#efefef" style="padding: 0; margin: 0" | ||
| table border="0" cellpadding="0" cellspacing="0" width="100%" | ||
| tr | ||
| td align="center" | ||
| table width="600" border="0" cellpadding="30" cellspacing="0" | ||
| ==render 'header' | ||
| ==render 'body', object: @task, action: 'updated' | ||
| ==render 'footer' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| h4 Reset your password | ||
| = simple_form_for :user, url: password_resets_path(token: params[:token]), method: :put do |f| | ||
| p | ||
| = f.input :password | ||
| = f.input :password_confirmation | ||
| p | ||
| = f.button :submit, "Change pass" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| h4 Forgot password? No problem! | ||
| p Type your email here, we'll send you link. | ||
| = simple_form_for :user, url: password_resets_path do |f| | ||
| p | ||
| = f.input :email | ||
| p | ||
| = f.button :submit, "Send" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AddResetPasswordTokenToUsers < ActiveRecord::Migration[6.0] | ||
| def change | ||
| add_column :users, :reset_password_token_digest, :string | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,8 @@ version: '3.7' | |
| services: | ||
| web: | ||
| build: . | ||
| volumes: &web-volumes | ||
| volumes: | ||
| &web-volumes | ||
| - &app-volume .:/task_manager:cached | ||
| - ~/.ssh:/root/.ssh | ||
| - ~/.bash_history:/root/.bash_history | ||
|
|
@@ -14,7 +15,8 @@ services: | |
| - 3332:3332 | ||
| depends_on: | ||
| - db | ||
| environment: &web-environment | ||
| environment: | ||
| &web-environment | ||
| BUNDLE_PATH: /bundle_cache | ||
| GEM_HOME: /bundle_cache | ||
| GEM_PATH: /bundle_cache | ||
|
|
@@ -23,6 +25,13 @@ services: | |
| DATABASE_HOST: db | ||
| DATABASE_USERNAME: postgres | ||
| DATABASE_PASSWORD: postgres | ||
|
|
||
| MAILER_USERNAME: fake | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не очень решение. Пересобирать контейнер при добавлении/удалении переменных не очень хочется |
||
| MAILER_PASSWORD: fake | ||
| MAILER_ADDRESS: fake | ||
| MAILER_PORT: fake | ||
| MAILER_DOMAIN: fake | ||
| MAILER_AUTHENTICATION: fake | ||
| command: bundle exec rails s -b '0.0.0.0' -p 3330 | ||
|
|
||
| db: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше через стронг параметры