Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Dynamic translation and Post view configuration changes #758

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flask_security/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
'POST_LOGOUT_VIEW': '/',
'CONFIRM_ERROR_VIEW': None,
'POST_REGISTER_VIEW': None,
'POST_FORGOT_VIEW': None,
'POST_SEND_CONFIRMATION_VIEW': None,
'POST_CONFIRM_VIEW': None,
'POST_RESET_VIEW': None,
'POST_CHANGE_VIEW': None,
Expand Down
4 changes: 3 additions & 1 deletion flask_security/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@

class ValidatorMixin(object):
def __call__(self, form, field):
# This is a fix that avoids the API being changed.
if self.message and self.message.isupper():
self.message = get_message(self.message)[0]
self.message_key = self.message
self.message = get_message(self.message_key)[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the self.message_key is not set?

Can we change the Validator mixin to something around this lines?

class ValidatorMixin(object):
   
    @property
    def message(self):
        if self._templated:
            return get_message(self._message)[0]
        return self._message

    @message.setter
    def message(self, value):
        self._templated = value and value.isupper()
        self._message = value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did I miss that? :)

I'm ok with properties.
Do you want me to put it into this Pull Request?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kantorii yes, you can update this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jirikuncar Thanks for the wait. The suggested change is on the branch now.

return super(ValidatorMixin, self).__call__(form, field)


Expand Down
4 changes: 3 additions & 1 deletion flask_security/registerable.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def register_user(**kwargs):

if _security.confirmable:
confirmation_link, token = generate_confirmation_link(user)
do_flash(*get_message('CONFIRM_REGISTRATION', email=user.email))

user_registered.send(app._get_current_object(),
user=user, confirm_token=token)
Expand All @@ -40,4 +39,7 @@ def register_user(**kwargs):
'welcome', user=user,
confirmation_link=confirmation_link)

if _security.confirmable:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kantorii can you please clarify why do we need to move the do_flash call to the separate block?

Copy link
Contributor Author

@kantorii kantorii Jul 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. If there is an exception within user_registered.send(), do_flash() will not be executed.
I believe it should be that way, because, if I remember correctly, the flash says an email was sent.

do_flash(*get_message('CONFIRM_REGISTRATION', email=user.email))

return user
328 changes: 328 additions & 0 deletions flask_security/translations/ja_JP/LC_MESSAGES/flask_security.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
# Translations template for Flask-Security.
# Copyright (C) 2017 CERN
# This file is distributed under the same license as the Flask-Security
# project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2017.
#
msgid ""
msgstr ""
"Project-Id-Version: Flask-Security 2.0.1\n"
"Report-Msgid-Bugs-To: info@inveniosoftware.org\n"
"POT-Creation-Date: 2017-06-06 13:23+0200\n"
"PO-Revision-Date: 2018-01-25 14:12+0900\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.4.0\n"
"X-Generator: Poedit 2.0.6\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=1; plural=0;\n"
"Language: ja\n"

#: flask_security/core.py:99
msgid "Login Required"
msgstr "ログインが必要です"

#: flask_security/core.py:100
msgid "Welcome"
msgstr "ようこそ"

#: flask_security/core.py:101
msgid "Please confirm your email"
msgstr "メール アドレスの検証"

#: flask_security/core.py:102
msgid "Login instructions"
msgstr "ログイン手順"

#: flask_security/core.py:103
#: flask_security/templates/security/email/reset_notice.html:1
msgid "Your password has been reset"
msgstr "パスワード変更"

#: flask_security/core.py:104
msgid "Your password has been changed"
msgstr "パスワードが変更されました。"

#: flask_security/core.py:106
msgid "Password reset instructions"
msgstr "パスワード再設定手順"

#: flask_security/core.py:132
msgid "You do not have permission to view this resource."
msgstr "アクセス権がありません"

#: flask_security/core.py:134
#, python-format
msgid "Thank you. Confirmation instructions have been sent to %(email)s."
msgstr ""
"ご登録ありがとうございます。%(email)sにメール アドレス検証手順が送信されま"
"した。"

#: flask_security/core.py:138
msgid "Thank you. Your email has been confirmed."
msgstr "ありがとうございます。メール アドレスが検証されました。"

#: flask_security/core.py:140
msgid "Your email has already been confirmed."
msgstr "メール アドレスは検証済みです"

#: flask_security/core.py:142
msgid "Invalid confirmation token."
msgstr "リンクが無効です"

#: flask_security/core.py:144
#, python-format
msgid "%(email)s is already associated with an account."
msgstr "%(email)s のアカウントは既に作成されています"

#: flask_security/core.py:146
msgid "Password does not match"
msgstr "パスワードが一致しません"

#: flask_security/core.py:148
msgid "Passwords do not match"
msgstr "入力したパスワードが一致していません"

#: flask_security/core.py:150
msgid "Redirections outside the domain are forbidden"
msgstr "ドメイン外へのリダイレクトは禁止されています"

#: flask_security/core.py:152
#, python-format
msgid "Instructions to reset your password have been sent to %(email)s."
msgstr "パスワードの再設定手順が %(email)s に送信されました"

#: flask_security/core.py:155
#, python-format
msgid ""
"You did not reset your password within %(within)s. New instructions have "
"been sent to %(email)s."
msgstr ""
"%(within)s以内にパスワードを設定しませんでした。パスワード再設定手順を "
"%(email)s に再度送信しました。"

#: flask_security/core.py:158
msgid "Invalid reset password token."
msgstr "リンクが無効です"

#: flask_security/core.py:160
msgid "Email requires confirmation."
msgstr "メール アドレスの検証が必要です"

#: flask_security/core.py:162
#, python-format
msgid "Confirmation instructions have been sent to %(email)s."
msgstr "%(email)sにメール アドレス検証手順が再送信されました"

#: flask_security/core.py:164
#, python-format
msgid ""
"You did not confirm your email within %(within)s. New instructions to "
"confirm your email have been sent to %(email)s."
msgstr ""
"%(within)s以内にメール アドレスが検証されませんでした。新しい検証手順を "
"%(email)s に送信しました。"

#: flask_security/core.py:168
#, python-format
msgid ""
"You did not login within %(within)s. New instructions to login have been "
"sent to %(email)s."
msgstr ""
"%(within)s以内にログインしませんでした。ログイン手順を %(email)s に再度送"
"信しました。"

#: flask_security/core.py:171
#, python-format
msgid "Instructions to login have been sent to %(email)s."
msgstr "%(email)sにログイン手順が送信されました"

#: flask_security/core.py:173
msgid "Invalid login token."
msgstr "リンクが無効です"

#: flask_security/core.py:175
msgid "Account is disabled."
msgstr "アカウントが無効になっています"

#: flask_security/core.py:177
msgid "Email not provided"
msgstr "メール アドレスを入力してください"

#: flask_security/core.py:179
msgid "Invalid email address"
msgstr "正しいメール アドレスを入力してください"

#: flask_security/core.py:181
msgid "Password not provided"
msgstr "パスワードを入力してください"

#: flask_security/core.py:183
msgid "No password is set for this user"
msgstr "パスワードが設定されていません"

#: flask_security/core.py:185
msgid "Password must be at least 6 characters"
msgstr "パスワードは6文字以上でなければなりません"

#: flask_security/core.py:187
msgid "Specified user does not exist"
msgstr "入力を確認してください"

#: flask_security/core.py:189
msgid "Invalid password"
msgstr "入力を確認してください"

#: flask_security/core.py:191
msgid "You have successfully logged in."
msgstr "ログインしました"

#: flask_security/core.py:193
msgid "Forgot password?"
msgstr "パスワードを忘れた場合"

#: flask_security/core.py:195
msgid ""
"You successfully reset your password and you have been logged in "
"automatically."
msgstr "パスワードの再設定が完了しました。"

#: flask_security/core.py:198
msgid "Your new password must be different than your previous password."
msgstr "新旧パスワードが同じです"

#: flask_security/core.py:201
msgid "You successfully changed your password."
msgstr "パスワードが変更されました"

#: flask_security/core.py:203
msgid "Please log in to access this page."
msgstr "ログインしてください"

#: flask_security/core.py:205
msgid "Please reauthenticate to access this page."
msgstr "再度ログインしてください"

#: flask_security/forms.py:30
msgid "Email Address"
msgstr "メール アドレス"

#: flask_security/forms.py:31
msgid "Password"
msgstr "パスワード"

#: flask_security/forms.py:32
msgid "Remember Me"
msgstr "次回以降ログインを省略する"

#: flask_security/forms.py:33 flask_security/templates/security/_menu.html:4
#: flask_security/templates/security/login_user.html:3
#: flask_security/templates/security/send_login.html:3
msgid "Login"
msgstr "ログイン"

#: flask_security/forms.py:34 flask_security/templates/security/_menu.html:6
#: flask_security/templates/security/register_user.html:3
msgid "Register"
msgstr "ユーザ登録"

#: flask_security/forms.py:35
msgid "Resend Confirmation Instructions"
msgstr "検証手順の再送信"

#: flask_security/forms.py:36
msgid "Recover Password"
msgstr "再設定手順を送信"

#: flask_security/forms.py:37
msgid "Reset Password"
msgstr "パスワード変更"

#: flask_security/forms.py:38
msgid "Retype Password"
msgstr "パスワード再入力"

#: flask_security/forms.py:39
msgid "New Password"
msgstr "新しいパスワード"

#: flask_security/forms.py:40
msgid "Change Password"
msgstr "変更"

#: flask_security/forms.py:41
msgid "Send Login Link"
msgstr "ログイン手順を送信"

#: flask_security/templates/security/_menu.html:2
msgid "Menu"
msgstr "メニュー"

#: flask_security/templates/security/_menu.html:9
msgid "Forgot password"
msgstr "パスワードを忘れた場合"

#: flask_security/templates/security/_menu.html:12
msgid "Confirm account"
msgstr "メール アドレスの検証"

#: flask_security/templates/security/change_password.html:3
msgid "Change password"
msgstr "パスワードの変更"

#: flask_security/templates/security/forgot_password.html:3
msgid "Send password reset instructions"
msgstr "パスワード再設定手順の送信"

#: flask_security/templates/security/reset_password.html:3
msgid "Reset password"
msgstr "パスワード再設定"

#: flask_security/templates/security/send_confirmation.html:3
msgid "Resend confirmation instructions"
msgstr "検証手順の再送信"

#: flask_security/templates/security/email/change_notice.html:1
msgid "Your password has been changed."
msgstr "パスワードが変更されました。"

#: flask_security/templates/security/email/change_notice.html:3
msgid "If you did not change your password,"
msgstr "パスワードを変更した覚えがない場合には、"

#: flask_security/templates/security/email/change_notice.html:3
msgid "click here to reset it"
msgstr "このリンクを開いてください。"

#: flask_security/templates/security/email/confirmation_instructions.html:1
msgid "Please confirm your email through the link below:"
msgstr "以下のリンクからメール アドレスを検証してください:"

#: flask_security/templates/security/email/confirmation_instructions.html:3
#: flask_security/templates/security/email/welcome.html:6
msgid "Confirm my account"
msgstr "メール アドレスの検証"

#: flask_security/templates/security/email/login_instructions.html:1
#: flask_security/templates/security/email/welcome.html:1
#, python-format
msgid "Welcome %(email)s!"
msgstr "ようこそ %(email)s !"

#: flask_security/templates/security/email/login_instructions.html:3
msgid "You can log into your account through the link below:"
msgstr "以下のリンクによりログインできます。"

#: flask_security/templates/security/email/login_instructions.html:5
msgid "Login now"
msgstr "ログイン"

#: flask_security/templates/security/email/reset_instructions.html:1
msgid "Click here to reset your password"
msgstr "パスワードを再設定するためにこのリンクを開いてください。"

#: flask_security/templates/security/email/welcome.html:4
msgid "You can confirm your email through the link below:"
msgstr "以下のリンクによりメール アドレスを検証できます。"
6 changes: 6 additions & 0 deletions flask_security/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ def send_confirmation():
do_flash(*get_message('CONFIRMATION_REQUEST',
email=form.user.email))

if _security.post_send_confirmation_view:
return redirect(get_url(_security.post_send_confirmation_view))

if request.is_json:
return _render_json(form)

Expand Down Expand Up @@ -261,6 +264,9 @@ def forgot_password():
do_flash(*get_message('PASSWORD_RESET_REQUEST',
email=form.user.email))

if _security.post_forgot_view:
return redirect(get_url(_security.post_forgot_view))

if request.is_json:
return _render_json(form, include_user=False)

Expand Down