Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
00744c6b
Commit
00744c6b
authored
Dec 13, 2018
by
Ivan Tashkinov
Browse files
[#114] Initial implementation of user email invitations.
parent
90894335
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/emails/user_email.ex
View file @
00744c6b
...
...
@@ -9,10 +9,13 @@ defp instance_config, do: Pleroma.Config.get(:instance)
defp
instance_name
,
do
:
instance_config
()[
:name
]
defp
from
do
defp
sender
do
{
instance_name
(),
instance_config
()[
:email
]}
end
defp
recipient
(
email
,
nil
),
do
:
email
defp
recipient
(
email
,
name
),
do
:
{
name
,
email
}
def
password_reset_email
(
user
,
password_reset_token
)
when
is_binary
(
password_reset_token
)
do
password_reset_url
=
Router
.
Helpers
.
util_url
(
...
...
@@ -29,9 +32,30 @@ def password_reset_email(user, password_reset_token) when is_binary(password_res
"""
new
()
|>
to
(
{
user
.
name
,
user
.
email
}
)
|>
from
(
from
())
|>
to
(
recipient
(
user
.
email
,
user
.
name
)
)
|>
from
(
sender
())
|>
subject
(
"Password reset"
)
|>
html_body
(
html_body
)
end
def
user_invitation_email
(
user
,
to_email
,
to_name
\\
nil
)
do
registration_url
=
Router
.
Helpers
.
redirect_url
(
Endpoint
,
:registration_page
,
""
)
html_body
=
"""
<h3>You are invited to #{instance_name()}</h3>
<p>#{user.name} invites you to join #{instance_name()}, an instance of Pleroma federated social networking platform.</p>
<p>Click the following link to register: <a href="#{registration_url}">accept invitation</a>.</p>
"""
new
()
|>
to
(
recipient
(
to_email
,
to_name
))
|>
from
(
sender
())
|>
subject
(
"Invitation to
#{
instance_name
()
}
"
)
|>
html_body
(
html_body
)
end
end
lib/pleroma/web/twitter_api/controllers/util_controller.ex
View file @
00744c6b
...
...
@@ -168,7 +168,7 @@ def config(conn, _params) do
private:
if
(
Keyword
.
get
(
instance
,
:public
,
true
),
do
:
"0"
,
else
:
"1"
),
accountActivationRequired:
if
(
Keyword
.
get
(
instance
,
:account_activation_required
,
false
),
do
:
"1"
,
else
:
"0"
),
invitesEnabled:
if
(
Keyword
.
get
(
instance
,
:invites_enabled
,
tru
e
),
do
:
"1"
,
else
:
"0"
),
invitesEnabled:
if
(
Keyword
.
get
(
instance
,
:invites_enabled
,
fals
e
),
do
:
"1"
,
else
:
"0"
),
vapidPublicKey:
vapid_public_key
}
...
...
lib/pleroma/web/twitter_api/twitter_api_controller.ex
View file @
00744c6b
...
...
@@ -335,7 +335,13 @@ def password_reset(conn, params) do
def
confirm_email
(
_conn
,
_params
),
do
:
:noop
def
email_invite
(
_conn
,
_params
),
do
:
:noop
def
email_invite
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"email"
=>
email
}
=
params
)
do
with
true
<-
Pleroma
.
Config
.
get
([
:instance
,
:invites_enabled
]),
email
<-
Pleroma
.
UserEmail
.
user_invitation_email
(
user
,
email
,
params
[
"name"
]),
{
:ok
,
_
}
<-
Pleroma
.
Mailer
.
deliver
(
email
)
do
json_response
(
conn
,
:no_content
,
""
)
end
end
def
update_avatar
(%{
assigns:
%{
user:
user
}}
=
conn
,
params
)
do
{
:ok
,
object
}
=
ActivityPub
.
upload
(
params
,
type:
:avatar
)
...
...
test/web/twitter_api/twitter_api_controller_test.exs
View file @
00744c6b
...
...
@@ -873,6 +873,38 @@ test "it returns 500 when user is not local", %{conn: conn, user: user} do
end
end
describe
"POST /api/email_invite, with valid parameters"
do
setup
[
:valid_user
]
setup
do
invites_enabled
=
Pleroma
.
Config
.
get
([
:instance
,
:invites_enabled
])
Pleroma
.
Config
.
put
([
:instance
,
:invites_enabled
],
true
)
on_exit
(
fn
->
Pleroma
.
Config
.
put
([
:instance
,
:invites_enabled
],
invites_enabled
)
:ok
end
)
:ok
end
test
"it returns 204"
,
%{
conn:
conn
,
user:
user
}
do
recipient_email
=
"foo@bar.com"
recipient_name
=
"J. D."
conn
=
conn
|>
assign
(
:user
,
user
)
|>
post
(
"/api/email_invite?email=
#{
recipient_email
}
&name=
#{
recipient_name
}
"
)
assert
json_response
(
conn
,
:no_content
)
Swoosh
.
TestAssertions
.
assert_email_sent
(
Pleroma
.
UserEmail
.
user_invitation_email
(
user
,
recipient_email
,
recipient_name
)
)
end
end
describe
"GET /api/externalprofile/show"
do
test
"it returns the user"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment