Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes-Bug: #1298734 Change-Id: I800b95a5c7617a9493f83059fd97240d3d1968cb
- Loading branch information
1 parent
1e2bee6
commit 880c123
Showing
11 changed files
with
300 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from django.conf import settings | ||
from django.core.mail import send_mail | ||
from django import forms | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from horizon.forms import SelfHandlingForm | ||
from horizon import messages | ||
|
||
from wildcard.api import keystone | ||
|
||
|
||
class ForgotUsernameForm(SelfHandlingForm): | ||
|
||
email = forms.CharField() | ||
|
||
user = None | ||
|
||
def clean(self): | ||
cleaned_data = super(ForgotUsernameForm, self).clean() | ||
email = cleaned_data.get('email') | ||
if email: | ||
self.user = keystone.user_find(None, email=email) | ||
if not self.user: | ||
raise forms.ValidationError( | ||
_("there is no user with such email") | ||
) | ||
return cleaned_data | ||
|
||
def handle(self, request, data): | ||
send_mail( | ||
_('username reminder'), | ||
_('your username is %s') % self.user.name, | ||
settings.DEFAULT_FROM_EMAIL, | ||
[self.user.email], | ||
) | ||
messages.success( | ||
request, | ||
_('your username was sent by email') | ||
) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% extends "horizon/common/_modal_form.html" %} | ||
{% load i18n %} | ||
{% load url from future %} | ||
|
||
{% block form_id %}forgot_username_form{% endblock %} | ||
{% block form_action %}{% url 'forgot-username' %}{% endblock %} | ||
|
||
{% block modal-header %}{% trans "Forgot Username" %}{% endblock %} | ||
|
||
{% block modal-body %} | ||
<div class="left"> | ||
<fieldset> | ||
{% include "horizon/common/_form_fields.html" %} | ||
</fieldset> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block modal-footer %} | ||
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Remind Username" %}" /> | ||
<a href="{% url 'login' %}" class="btn secondary cancel close">{% trans "Cancel" %}</a> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{% extends "horizon/common/_modal_form.html" %} | ||
{% load i18n %} | ||
{% load url from future %} | ||
|
||
{% block modal-header %}{% trans "Log In" %}{% endblock %} | ||
{% block modal_class %}login {% if hide %}modal hide{% endif %}{% endblock %} | ||
|
||
{% block form_action %}{% url 'login' %}{% endblock %} | ||
{% block autocomplete %}{{ HORIZON_CONFIG.password_autocomplete }}{% endblock %} | ||
|
||
{% block modal-body %} | ||
<fieldset> | ||
{% if request.user.is_authenticated and 'next' in request.GET %} | ||
<div class="control-group clearfix error"> | ||
<span class="help-inline"><p>{% trans "You do not have permission to access the resource:" %}</p> | ||
<p><b>{{ request.GET.next }}</b></p> | ||
<p>{% url 'horizon:user_home' as home_url %}{% blocktrans %}Login as different user or go back to <a href="{{ home_url }}"> home page</a>{% endblocktrans %}</p> | ||
</span> | ||
</div> | ||
{% endif %} | ||
{% if request.COOKIES.logout_reason %} | ||
<div class="control-group clearfix error"> | ||
<span class="help-inline"><p>{{ request.COOKIES.logout_reason }}</p></span> | ||
</div> | ||
{% endif %} | ||
{% if next %}<input type="hidden" name="{{ redirect_field_name }}" value="{{ next }}" />{% endif %} | ||
{% include "horizon/common/_form_fields.html" %} | ||
</fieldset> | ||
{% endblock %} | ||
|
||
{% block modal-footer %} | ||
<button type="submit" class="btn btn-primary pull-right">{% trans "Sign In" %}</button> | ||
<a href="{% url 'forgot-username' %}" class="ajax-modal">{% trans "Forgot Username?" %}</a> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% load branding %} | ||
{% load i18n %} | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' /> | ||
<title>{% trans "Forgot Username" %} - {% site_branding %}</title> | ||
{% include "_stylesheets.html" %} | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div id='main_content'> | ||
{% include '_forgot-username.html' %} | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% load branding %} | ||
{% load i18n %} | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' /> | ||
<title>{% trans "Login" %} - {% site_branding %}</title> | ||
{% include "_stylesheets.html" %} | ||
{% include "horizon/_conf.html" %} | ||
{% include "horizon/client_side/_script_loader.html" %} | ||
</head> | ||
<body id="splash" ng-app='horizonApp'> | ||
<div id="container"> | ||
<div id='main_content'> | ||
{% include "horizon/_messages.html" %} | ||
{% include 'auth/_login.html' %} | ||
</div> | ||
</div> | ||
{% include "horizon/_scripts.html" %} | ||
<div id="modal_wrapper" /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from django.core.urlresolvers import reverse | ||
|
||
from wildcard import api | ||
from wildcard.test import helpers as test | ||
|
||
|
||
SPLASH_URL = reverse('splash') | ||
FORGOT_USERNAME_URL = reverse('forgot-username') | ||
|
||
|
||
class ForgotUsernameTests(test.TestCase): | ||
|
||
@test.create_stubs({api.keystone: ('user_find',)}) | ||
def test_existent_email(self): | ||
user = self.users.get(id='1') | ||
api.keystone.user_find( | ||
None, | ||
email=user.email, | ||
).AndReturn(user) | ||
self.mox.ReplayAll() | ||
|
||
formData = { | ||
'method': 'ForgotUsernameForm', | ||
'email': user.email, | ||
} | ||
res = self.client.post(FORGOT_USERNAME_URL, formData) | ||
|
||
self.assertNoFormErrors(res) | ||
self.assertRedirectsNoFollow(res, SPLASH_URL) | ||
self.assertMessageCount(success=1) | ||
|
||
@test.create_stubs({api.keystone: ('user_find',)}) | ||
def test_nonexistent_email(self): | ||
user = self.users.get(id='1') | ||
api.keystone.user_find( | ||
None, | ||
email=user.email, | ||
).AndReturn(None) | ||
self.mox.ReplayAll() | ||
|
||
formData = { | ||
'method': 'ForgotUsernameForm', | ||
'email': user.email, | ||
} | ||
res = self.client.post(FORGOT_USERNAME_URL, formData) | ||
|
||
self.assertFormErrors(res, count=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
# vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import horizon | ||
|
||
from django.conf.urls import patterns, include, url | ||
|
||
from wildcard.views import ForgotUsername | ||
|
||
urlpatterns = patterns( | ||
'', | ||
url(r'^$', 'wildcard.views.splash', name='splash'), | ||
url(r'^auth/', include('openstack_auth.urls')), | ||
url(r'', include(horizon.urls)) | ||
url(r'', include(horizon.urls)), | ||
url( | ||
r'^forgot-username$', | ||
ForgotUsername.as_view(), | ||
name='forgot-username', | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters