Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit746d9f9

Browse files
committed
chore: Merge branch 'emails' into dev
2 parents6638dbc +8d6fc93 commit746d9f9

File tree

22 files changed

+1792
-7
lines changed

22 files changed

+1792
-7
lines changed

‎config/config.exs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ config :groupher_server, :customization,
6666

6767
config:groupher_server,GroupherServerWeb.Gettext,default_locale:"zh_CN",locales:~w(en zh_CN)
6868

69+
# config email services
70+
config:groupher_server,:system_emails,
71+
support:"coderplanets <support@group.coderplanets.com>",
72+
admin:"mydearxym@qq.com"
73+
74+
config:groupher_server,GroupherServer.Mailer,
75+
adapter:Bamboo.MailgunAdapter,
76+
domain:"mailer.coderplanets.com"
77+
6978
import_config"#{Mix.env()}.exs"
7079

7180
ifFile.exists?("config/#{Mix.env()}.secret.exs")do

‎config/dev.exs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ config :groupher_server, GroupherServer.Repo,
5454
config:groupher_server,:github_oauth,
5555
client_id:System.get_env("OAUTH_GITHUB_CLIENT_ID"),
5656
client_secret:System.get_env("OAUTH_GITHUB_CLIENT_SECRET")
57+
58+
# config email services
59+
config:groupher_server,GroupherServer.Mailer,api_key:System.get_env("MAILER_API_KEY")

‎config/mock.exs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ config :groupher_server, GroupherServer.Repo,
1919
database:"groupher_server_mock",
2020
hostname:"localhost",
2121
pool_size:10
22+
23+
# config email services
24+
config:groupher_server,GroupherServer.Mailer,adapter:Bamboo.LocalAdapter

‎config/prod.exs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,6 @@ config :sentry,
9595
env:"production"
9696
},
9797
included_environments:[:prod]
98+
99+
# config email services
100+
config:groupher_server,GroupherServer.Mailer,api_key:System.get_env("MAILER_API_KEY")

‎config/test.exs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ config :groupher_server, GroupherServer.Repo,
2525
config:groupher_server,:github_oauth,
2626
client_id:"3b4281c5e54ffd801f85",
2727
client_secret:"51f04dd8239b27f00a39a647ef3704de4c5ddc26"
28+
29+
# config email services
30+
config:groupher_server,GroupherServer.Mailer,adapter:Bamboo.TestAdapter

‎lib/groupher_server/accounts/delegates/profile.ex‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ defmodule GroupherServer.Accounts.Delegate.Profile do
1010
aliasHelper.{Guardian,ORM,QueryBuilder,RadarSearch}
1111
aliasGroupherServer.Accounts.{Achievement,GithubUser,User,Social}
1212
aliasGroupherServer.{CMS,Repo}
13+
aliasGroupherServer.Email
1314

1415
aliasEcto.Multi
1516

@@ -149,7 +150,14 @@ defmodule GroupherServer.Accounts.Delegate.Profile do
149150
|>register_github_result
150151
end
151152

152-
defpregister_github_result({:ok,%{create_user:user}}),do:gen_token(user)
153+
defpregister_github_result({:ok,%{create_user:create_user}})do
154+
{:ok,user}=ORM.find(User,create_user.id,preload::github_profile)
155+
156+
Email.welcome(user)
157+
Email.notify_admin(user,:new_register)
158+
159+
gen_token(user)
160+
end
153161

154162
defpregister_github_result({:error,:create_user,%Ecto.Changeset{}=result,_steps}),
155163
do:{:error,result}

‎lib/groupher_server/billing/delegates/curd.ex‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule GroupherServer.Billing.Delegate.CURD do
1212
aliasGroupherServer.Billing.BillRecord
1313
aliasGroupherServer.Billing.Delegate.Actions
1414
aliasGroupherServer.Repo
15+
aliasGroupherServer.Email
1516

1617
aliasEcto.Multi
1718

@@ -87,6 +88,13 @@ defmodule GroupherServer.Billing.Delegate.CURD do
8788
|>Map.merge(~m(user_id hash_id state)a)
8889
|>map_atom_value(:string)
8990

90-
BillRecord|>ORM.create(attrs)
91+
# {:ok, record} = BillRecord |> ORM.create(attrs)
92+
# TODO:
93+
{:ok,record}=BillRecord|>ORM.create(attrs)
94+
# IO.inspect(record, label: "record ->")
95+
Email.notify_admin(record,:payment)
96+
# {:ok, record} = BillRecord |> ORM.create(attrs, {after_success: })
97+
# i email to admin
98+
{:ok,record}
9199
end
92100
end

‎lib/groupher_server/cms/utils/loader.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ defmodule GroupherServer.CMS.Utils.Loader do
178178
# NOTE: this is NOT the right solution
179179
# should use WINDOW function
180180
# see https://github.com/coderplanets/coderplanets_server/issues/16
181-
defquery({"posts_comments",PostComment},%{filter:filter,unique:true})do
181+
defquery({"posts_comments",PostComment},%{filter:_filter,unique:true})do
182182
PostComment
183183
|>join(:inner,[c],ainassoc(c,:author))
184184
# NOTE: this distinct not working in production env, so the uniq logic is move to
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
defmoduleGroupherServer.Emaildo
2+
@moduledoc"""
3+
the email dispatch system for Groupher
4+
5+
welcom_email -> send to new register
6+
"""
7+
importBamboo.Email
8+
importHelper.Utils,only:[get_config:2]
9+
10+
aliasGroupherServer.Accounts.User
11+
aliasGroupherServer.Billing.BillRecord
12+
13+
aliasGroupherServer.Email.Templates
14+
aliasGroupherServer.Mailer
15+
16+
@support_emailget_config(:system_emails,:support)
17+
@admin_emailget_config(:system_emails,:admin)
18+
19+
defwelcome(%User{email:email}=user)whennotis_nil(email)do
20+
base_mail()
21+
|>to(email)
22+
|>subject("欢迎来到 coderplanets")
23+
|>html_body(Templates.Welcome.html(user))
24+
|>text_body(Templates.Welcome.text())
25+
|>Mailer.deliver_later()
26+
end
27+
28+
# user has no email log to somewhere
29+
defwelcome(_user)do
30+
{:ok,:pass}
31+
end
32+
33+
defnotify_admin(%User{from_github:true}=user,:new_register)do
34+
base_mail()
35+
|>to(@admin_email)
36+
|>subject("新用户(#{user.nickname})注册")
37+
|>html_body(Templates.NotifyAdminRegister.html(user))
38+
|>text_body(Templates.NotifyAdminRegister.text())
39+
|>Mailer.deliver_later()
40+
end
41+
42+
defnotify_admin(_user,:new_register)do
43+
{:ok,:pass}
44+
end
45+
46+
defnotify_admin(%BillRecord{}=record,:payment)do
47+
base_mail()
48+
|>to(@admin_email)
49+
|>subject("打赏#{record.amount} 元")
50+
|>html_body(Templates.NotifyAdminPayment.html(record))
51+
|>text_body(Templates.NotifyAdminPayment.text())
52+
|>Mailer.deliver_later()
53+
end
54+
55+
# some one comment to your post ..
56+
# the author's publish content being deleted ..
57+
defnotify_author,do:IO.inspect("notify_author")
58+
defnotify_publish,do:IO.inspect("notify_publish")
59+
# ...
60+
61+
defpbase_maildo
62+
new_email()
63+
|>from(@support_email)
64+
end
65+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
defmoduleGroupherServer.Mailerdo
2+
@moduledoc"""
3+
the email staff for Groupher
4+
"""
5+
useBamboo.Mailer,otp_app::groupher_server
6+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp