FEATURE: add email query param to login, signup, and password-reset URLs to prefill form

This commit is contained in:
Neil Lalonde 2016-01-19 16:53:46 -05:00
parent 11ea16a91a
commit 9ad226aaa8
6 changed files with 28 additions and 6 deletions

View File

@ -7,6 +7,12 @@ export default Ember.Controller.extend(ModalFunctionality, {
return Ember.isEmpty((this.get('accountEmailOrUsername') || '').trim()) || this.get('disabled');
}.property('accountEmailOrUsername', 'disabled'),
onShow: function() {
if ($.cookie('email')) {
this.set('accountEmailOrUsername', $.cookie('email'));
}
},
actions: {
submit: function() {
var self = this;

View File

@ -6,9 +6,14 @@ export default ModalBodyView.extend({
classNames: ['create-account'],
_setup: function() {
// allows the submission the form when pressing 'ENTER' on *any* text input field
// but only when the submit button is enabled
// Allows submitting the form when pressing 'ENTER' on *any* text input field
// but only when the submit button is enabled.
const createAccountController = this.get('controller');
if ($.cookie('email')) {
createAccountController.set('accountEmail', $.cookie('email'));
}
Em.run.schedule('afterRender', function() {
$("input[type='text'], input[type='password']").keydown(function(e) {
if (createAccountController.get('submitDisabled') === false && e.keyCode === 13) {

View File

@ -15,8 +15,13 @@ export default ModalBodyView.extend({
// Get username and password from the browser's password manager,
// if it filled the hidden static login form:
loginController.set('loginName', $('#hidden-login-form input[name=username]').val());
loginController.set('loginPassword', $('#hidden-login-form input[name=password]').val());
var prefillUsername = $('#hidden-login-form input[name=username]').val();
if (prefillUsername) {
loginController.set('loginName', prefillUsername);
loginController.set('loginPassword', $('#hidden-login-form input[name=password]').val());
} else if ($.cookie('email')) {
loginController.set('loginName', $.cookie('email'));
}
Em.run.schedule('afterRender', function() {
$('#login-account-password, #login-account-name').keydown(function(e) {

View File

@ -6,8 +6,10 @@ class StaticController < ApplicationController
skip_before_filter :check_xhr, :redirect_to_login_if_required
skip_before_filter :verify_authenticity_token, only: [:cdn_asset, :enter, :favicon]
PAGES_WITH_EMAIL_PARAM = ['login', 'password_reset', 'signup']
def show
return redirect_to(path '/') if current_user && params[:id] == 'login'
return redirect_to(path '/') if current_user && (params[:id] == 'login' || params[:id] == 'signup')
map = {
"faq" => {redirect: "faq_url", topic_id: "guidelines_topic_id"},
@ -44,6 +46,10 @@ class StaticController < ApplicationController
return
end
if PAGES_WITH_EMAIL_PARAM.include?(@page) && params[:email]
cookies[:email] = { value: params[:email], expires: 1.day.from_now }
end
file = "static/#{@page}.#{I18n.locale}"
file = "static/#{@page}.en" if lookup_context.find_all("#{file}.html").empty?
file = "static/#{@page}" if lookup_context.find_all("#{file}.html").empty?

View File

View File

@ -255,7 +255,7 @@ Discourse::Application.routes.draw do
get "guidelines" => "static#show", id: "guidelines", as: 'guidelines'
get "tos" => "static#show", id: "tos", as: 'tos'
get "privacy" => "static#show", id: "privacy", as: 'privacy'
get "signup" => "list#latest"
get "signup" => "static#show", id: "signup"
get "login-preferences" => "static#show", id: "login"
get "users/admin-login" => "users#admin_login"