check if email is already in use when registering + some rtl css fixes

This commit is contained in:
Hannes Mannerheim 2015-12-14 21:01:27 +01:00
parent 1e81480f9b
commit 02eced7291
26 changed files with 225 additions and 42 deletions

View File

@ -141,7 +141,8 @@ class QvitterPlugin extends Plugin {
public function onRouterInitialized($m)
{
$m->connect('api/qvitter/check_email.json',
array('action' => 'ApiQvitterCheckEmail'));
$m->connect('api/qvitter/:nickname/lists/:id/subscribers.json',
array('action' => 'ApiQvitterListSubscribers',
'nickname' => '[a-zA-Z0-9]+',

View File

@ -0,0 +1,84 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Check email
*
* Returns 1 if email is already in use on this instance, 0 if not. Error if site is private.
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category API
* @package GNUsocial
* @author Hannes Mannerheim <h@nnesmannerhe.im>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://www.gnu.org/software/social/
*/
if (!defined('GNUSOCIAL')) { exit(1); }
class ApiQvitterCheckEmailAction extends ApiAction
{
var $email = null;
protected function prepare(array $args=array())
{
parent::prepare($args);
$this->email = $this->trimmed('email');
if(!Validate::email($this->email, common_config('email', 'check_domain'))) {
$this->clientError('Not a valid email address.', 400);
}
if (common_config('site', 'private')) {
$this->clientError(_('This site is private.'), 403);
}
return true;
}
protected function handle()
{
parent::handle();
if($this->emailExists($this->email)) {
$email_exists = 1;
} else {
$email_exists = 0;
}
$this->initDocument('json');
$this->showJsonObjects($email_exists);
$this->endDocument('json');
}
/**
* Does the given email address already exist?
*
* Checks a canonical email address against the database.
*
* @param string $email email address to check
*
* @return boolean true if the address already exists
*/
function emailExists($email)
{
$user = User::getKV('email', $email);
return is_object($user);
}
}

View File

@ -128,7 +128,8 @@ button.shorten i,
overflow: hidden;
}
#user-footer-inner .error-message,
.inline-reply-queetbox .error-message {
.inline-reply-queetbox .error-message,
.modal-content .error-message {
float:none;
}
.error-message pre code {
@ -737,6 +738,9 @@ body.rtl .front-welcome-text {
width:290px;
float:left;
}
body.rtl #login-register-container {
float: right;
}
#login-content,
.front-signup {
font-family: Arial,sans-serif;
@ -772,6 +776,7 @@ body.rtl .front-welcome-text {
position:relative;
margin-top:1px;
z-index:2000;
direction: ltr;
}
.front-signup {
margin-top:10px;
@ -816,7 +821,6 @@ body.rtl .front-welcome-text {
border-top-right-radius: 3px;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
box-shadow: 0 1px 0 #EEEEEE inset, 0 1px 0 #FFFFFF;
outline-color: #000000;
position: absolute;
display: block;
@ -1159,9 +1163,18 @@ button#submit-login:hover {
right: 3px;
top: 6px;
width: auto;
min-width: 50px;
text-align: left;
}
.modal-body .front-signup .fieldhelp.email-in-use {
color: red;
font-size: 10px;
font-style: italic;
line-height: 10px;
}
.modal-body .front-signup .signup-input-container input.invalid,
.modal-body .front-signup .signup-input-container input.nickname-taken {
.modal-body .front-signup .signup-input-container input.nickname-taken,
.modal-body .front-signup .signup-input-container input.email-in-use {
background-color:pink;
}
@ -1190,6 +1203,9 @@ button#submit-login:hover {
margin-left:-459px;
opacity:0;
}
body.rtl #page-container {
direction: rtl;
}
#footer {
width:100%;
@ -1291,6 +1307,10 @@ body.rtl #footer-spinner-container {
top: 0;
width: 32px;
}
body.rtl #history-container.menu-container a .chev-right {
right:auto;
left:0;
}
#history-container.menu-container a .chev-right::before {
content: '\f097';
color: #aaa;
@ -1586,7 +1606,7 @@ body.rtl #footer-spinner-container {
display: inline-block;
font-size: 20px;
line-height: 20px;
margin-left: 9px;
margin: 0 9px;
opacity: 0.4;
position: relative;
cursor:pointer;
@ -1833,6 +1853,9 @@ background-repeat: no-repeat;
list-style-type: none;
min-height: 85px;
}
.queet:not(.rtl) {
direction: ltr;
}
.stream-item.user .queet {
cursor: auto;
}
@ -2396,7 +2419,13 @@ body.rtl .view-more-container-bottom { direction:rtl; }
text-decoration: underline;
}
.stream-item-header .created-at:before {
content:" · ";
content: "·";
display: inline-block;
margin-left: 4px;
}
.queet.rtl .stream-item-header .created-at:before {
margin-right: 4px;
margin-left: 0;
}
.queet-text {
@ -2510,6 +2539,9 @@ ul.queet-actions li .icon {
ul.queet-actions li:not(:first-child) .icon {
margin-left:26px;
}
.queet.rtl ul.queet-actions .icon {
margin-left:26px;
}
.queet.rtl ul.queet-actions li .icon {
margin-right:0;
}
@ -5072,7 +5104,7 @@ body.rtl #top-compose {
margin-left:auto;
}
body.rtl .dropdown-caret.right {
body.rtl .topbar .dropdown-caret.right {
right: auto;
left: 10px;
}

View File

@ -1139,7 +1139,7 @@ function validateRegisterForm(o) {
if(fullname.val().length < 255) {
fullname.removeClass('invalid'); } else { fullname.addClass('invalid'); if(allFieldsValid)allFieldsValid=false; }
if(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email.val())) {
if(validEmail(email.val())) {
email.removeClass('invalid'); } else { email.addClass('invalid'); if(allFieldsValid)allFieldsValid=false; }
if($.trim(homepage.val()).length==0 || /^(ftp|http|https):\/\/[^ "]+$/.test(homepage.val())) {
@ -1157,6 +1157,15 @@ function validateRegisterForm(o) {
return allFieldsValid;
}
function validEmail(email) {
if(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email)) {
return true;
}
else {
return false;
}
}
/* ·
·
· Checks if edit profile form is valid

View File

@ -513,19 +513,51 @@ if(!window.registrationsClosed) {
// ask api if nickname is ok, if no typing for 1 s
$('#signup-user-nickname-step2').on('keyup',function(){
clearTimeout(window.checkNicknameTimeout);
if($('#signup-user-nickname-step2').val().length>1 && /^[a-zA-Z0-9]+$/.test($('#signup-user-nickname-step2').val())) {
$('#signup-user-nickname-step2').addClass('nickname-taken');
var thisInputElement = $(this);
var thisValue = $(this).val();
if(thisValue.length>1 && /^[a-zA-Z0-9]+$/.test(thisValue)) {
thisInputElement.addClass('nickname-taken');
if($('.spinner-wrap').length==0) {
$('#signup-user-nickname-step2').after('<div class="spinner-wrap"><div class="spinner"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></div></div>');
thisInputElement.after('<div class="spinner-wrap"><div class="spinner"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></div></div>');
}
window.checkNicknameTimeout = setTimeout(function(){
$.get(window.apiRoot + 'check_nickname.json?nickname=' + encodeURIComponent($('#signup-user-nickname-step2').val()),function(data){
$.get(window.apiRoot + 'check_nickname.json?nickname=' + encodeURIComponent(thisValue),function(data){
$('.spinner-wrap').remove();
if(data==0) {
$('#signup-user-password2-step2').trigger('keyup'); // revalidates
}
else {
$('#signup-user-nickname-step2').removeClass('nickname-taken');
thisInputElement.removeClass('nickname-taken');
$('#signup-user-password2-step2').trigger('keyup');
}
});
},1000);
}
else {
$('.spinner-wrap').remove();
}
});
// ask api if email is in use, if no typing for 1 s
$('#signup-user-email-step2').on('keyup',function(){
clearTimeout(window.checkEmailTimeout);
var thisInputElement = $(this);
var thisValue = $(this).val();
if(thisValue.length>1 && validEmail(thisValue)) {
thisInputElement.addClass('email-in-use');
if($('.spinner-wrap').length==0) {
thisInputElement.after('<div class="spinner-wrap"><div class="spinner"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></div></div>');
}
window.checkEmailTimeout = setTimeout(function(){
$.get(window.apiRoot + 'qvitter/check_email.json?email=' + encodeURIComponent(thisValue),function(data){
$('.spinner-wrap').remove();
if(data==1) {
$('#signup-user-password2-step2').trigger('keyup'); // revalidates
thisInputElement.after('<div class="fieldhelp email-in-use">' + window.sL.emailAlreadyInUse + '</div>');
}
else {
thisInputElement.removeClass('email-in-use');
thisInputElement.siblings('.fieldhelp.email-in-use').remove();
$('#signup-user-password2-step2').trigger('keyup');
}
});
@ -539,13 +571,10 @@ if(!window.registrationsClosed) {
// validate on keyup
$('#popup-register input').on('keyup',function(){
if(validateRegisterForm($('#popup-register'))) {
if(!$('#signup-user-nickname-step2').hasClass('nickname-taken')) {
$('#signup-btn-step2').removeClass('disabled');
}
else {
$('#signup-btn-step2').addClass('disabled');
}
if(validateRegisterForm($('#popup-register'))
&& !$('#signup-user-nickname-step2').hasClass('nickname-taken')
&& !$('#signup-user-email-step2').hasClass('email-in-use')) {
$('#signup-btn-step2').removeClass('disabled');
}
else {
$('#signup-btn-step2').addClass('disabled');
@ -580,7 +609,14 @@ if(!window.registrationsClosed) {
username: 'none',
},
dataType:"json",
error: function(data){ console.log('error'); console.log(data); },
error: function(data){
if(typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
remove_spinner();
$('#popup-register input,#popup-register button').removeClass('disabled');
$('#signup-user-password2-step2').trigger('keyup'); // revalidate
showErrorMessage(data.responseJSON.error,$('#popup-register .modal-header'));
}
},
success: function(data) {
remove_spinner();
if(typeof data.error == 'undefined') {

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"Meine Liste: {list-name}",
"listMembers":"Mitglieder",
"listSubscribers":"Abonnenten",
"ERRORcouldNotFindList":"Diese Liste gibt es nicht."
"ERRORcouldNotFindList":"Diese Liste gibt es nicht.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"Min liste: {list-name}",
"listMembers":"Medlemmer",
"listSubscribers":"Abonnenter",
"ERRORcouldNotFindList":"Det eksisterer ingen slik liste."
"ERRORcouldNotFindList":"Det eksisterer ingen slik liste.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -156,5 +156,6 @@
"myListWithListName":"Min lista: {list-name}",
"listMembers":"Listmedlemmar",
"listSubscribers":"Prenumeranter",
"ERRORcouldNotFindList":"Det finns ingen sådan lista."
"ERRORcouldNotFindList":"Det finns ingen sådan lista.",
"emailAlreadyInUse":"Används redan"
}

View File

@ -155,5 +155,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}

View File

@ -155,5 +155,6 @@
"myListWithListName":"My list: {list-name}",
"listMembers":"Members",
"listSubscribers":"Subscribers",
"ERRORcouldNotFindList":"There is no such list."
"ERRORcouldNotFindList":"There is no such list.",
"emailAlreadyInUse":"Already in use"
}