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
f5afb110
Commit
f5afb110
authored
Dec 11, 2018
by
Ivan Tashkinov
Browse files
[
#114
] Initial implementation of user password reset emails (user-initiated).
parent
12905ce1
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/emails/user_email.ex
0 → 100644
View file @
f5afb110
defmodule
Pleroma
.
UserEmail
do
@moduledoc
"User emails"
import
Swoosh
.
Email
alias
Pleroma
.
Web
.
{
Endpoint
,
Router
}
defp
instance_config
,
do
:
Pleroma
.
Config
.
get
(
:instance
)
defp
instance_name
,
do
:
instance_config
()[
:name
]
defp
from
do
{
instance_name
(),
instance_config
()[
:email
]}
end
def
password_reset_email
(
user
,
password_reset_token
)
when
is_binary
(
password_reset_token
)
do
password_reset_url
=
Router
.
Helpers
.
util_url
(
Endpoint
,
:show_password_reset
,
password_reset_token
)
html_body
=
"""
<h3>Reset your password at #{instance_name()}</h3>
<p>Someone has requested password change for your account at #{instance_name()}.</p>
<p>If it was you, visit the following link to proceed: <a href="#{password_reset_url}">reset password</a>.</p>
<p>If it was someone else, nothing to worry about: your data is secure and your password has not been changed.</p>
"""
new
()
|>
to
({
user
.
name
,
user
.
email
})
|>
from
(
from
())
|>
subject
(
"Password reset"
)
|>
html_body
(
html_body
)
end
end
lib/pleroma/web/router.ex
View file @
f5afb110
...
@@ -277,7 +277,7 @@ defmodule Pleroma.Web.Router do
...
@@ -277,7 +277,7 @@ defmodule Pleroma.Web.Router do
get
(
"/statusnet/conversation/:id"
,
TwitterAPI
.
Controller
,
:fetch_conversation
)
get
(
"/statusnet/conversation/:id"
,
TwitterAPI
.
Controller
,
:fetch_conversation
)
post
(
"/account/register"
,
TwitterAPI
.
Controller
,
:register
)
post
(
"/account/register"
,
TwitterAPI
.
Controller
,
:register
)
post
(
"/account/
reset_
password"
,
TwitterAPI
.
Controller
,
:
reset_
password
)
post
(
"/account/password
_reset
"
,
TwitterAPI
.
Controller
,
:password
_reset
)
get
(
"/search"
,
TwitterAPI
.
Controller
,
:search
)
get
(
"/search"
,
TwitterAPI
.
Controller
,
:search
)
get
(
"/statusnet/tags/timeline/:tag"
,
TwitterAPI
.
Controller
,
:public_and_external_timeline
)
get
(
"/statusnet/tags/timeline/:tag"
,
TwitterAPI
.
Controller
,
:public_and_external_timeline
)
...
...
lib/pleroma/web/twitter_api/twitter_api_controller.ex
View file @
f5afb110
defmodule
Pleroma
.
Web
.
TwitterAPI
.
Controller
do
defmodule
Pleroma
.
Web
.
TwitterAPI
.
Controller
do
use
Pleroma
.
Web
,
:controller
use
Pleroma
.
Web
,
:controller
import
Pleroma
.
Web
.
ControllerHelper
,
only:
[
json_response:
3
]
alias
Pleroma
.
Formatter
alias
Pleroma
.
Web
.
TwitterAPI
.
{
TwitterAPI
,
UserView
,
ActivityView
,
NotificationView
}
alias
Pleroma
.
Web
.
TwitterAPI
.
{
TwitterAPI
,
UserView
,
ActivityView
,
NotificationView
}
alias
Pleroma
.
Web
.
CommonAPI
alias
Pleroma
.
Web
.
CommonAPI
alias
Pleroma
.
{
Repo
,
Activity
,
Object
,
User
,
Notification
}
alias
Pleroma
.
{
Repo
,
Activity
,
Object
,
User
,
Notification
}
...
@@ -322,6 +326,21 @@ def register(conn, params) do
...
@@ -322,6 +326,21 @@ def register(conn, params) do
end
end
end
end
def
password_reset
(
conn
,
params
)
do
nickname_or_email
=
params
[
"email"
]
||
params
[
"nickname"
]
with
is_binary
(
nickname_or_email
),
%
User
{
local:
true
}
=
user
<-
User
.
get_by_nickname_or_email
(
nickname_or_email
)
do
{
:ok
,
token_record
}
=
Pleroma
.
PasswordResetToken
.
create_token
(
user
)
user
|>
Pleroma
.
UserEmail
.
password_reset_email
(
token_record
.
token
)
|>
Pleroma
.
Mailer
.
deliver
()
json_response
(
conn
,
:no_content
,
""
)
end
end
def
update_avatar
(%{
assigns:
%{
user:
user
}}
=
conn
,
params
)
do
def
update_avatar
(%{
assigns:
%{
user:
user
}}
=
conn
,
params
)
do
{
:ok
,
object
}
=
ActivityPub
.
upload
(
params
,
type:
:avatar
)
{
:ok
,
object
}
=
ActivityPub
.
upload
(
params
,
type:
:avatar
)
change
=
Changeset
.
change
(
user
,
%{
avatar:
object
.
data
})
change
=
Changeset
.
change
(
user
,
%{
avatar:
object
.
data
})
...
...
Write
Preview
Supports
Markdown
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