Use Ember.js for the `/u/account-created` path so we can add controls

This commit is contained in:
Robin Ward 2017-05-02 13:21:46 -04:00
parent 8048aeac22
commit b381372184
10 changed files with 48 additions and 14 deletions

View File

@ -20,6 +20,8 @@ export default {
DiscourseURL.rewrite(new RegExp(`^/u/${username}/?$`, "i"), `/u/${username}/activity`);
}
DiscourseURL.rewrite(/^\/u\/([^\/]+)\/?$/, "/u/$1/summary");
DiscourseURL.rewrite(/^\/u\/([^\/]+)\/?$/, "/u/$1/summary", {
exceptions: ['/u/account-created']
});
}
};

View File

@ -22,7 +22,12 @@ export function rewritePath(path) {
const params = path.split("?");
let result = params[0];
rewrites.forEach(rw => result = result.replace(rw.regexp, rw.replacement));
rewrites.forEach(rw => {
if (((rw.opts.exceptions || []).some(ex => path.indexOf(ex) === 0))) {
return;
}
result = result.replace(rw.regexp, rw.replacement);
});
if (params.length > 1) {
result += `?${params[1]}`;
@ -219,8 +224,8 @@ const DiscourseURL = Ember.Object.extend({
return this.handleURL(path, opts);
},
rewrite(regexp, replacement) {
rewrites.push({ regexp, replacement });
rewrite(regexp, replacement, opts) {
rewrites.push({ regexp, replacement, opts: opts || {} });
},
redirectTo(url) {

View File

@ -0,0 +1,7 @@
import PreloadStore from 'preload-store';
export default Ember.Route.extend({
setupController(controller) {
controller.set('accountCreated', PreloadStore.get('accountCreated'));
}
});

View File

@ -64,6 +64,7 @@ export default function() {
// User routes
this.route('users', { resetNamespace: true, path: '/u' });
this.route('password-reset', { path: '/u/password-reset/:token' });
this.route('account-created', { path: '/u/account-created' });
this.route('user', { path: '/u/:username', resetNamespace: true }, function() {
this.route('summary');
this.route('userActivity', { path: '/activity', resetNamespace: true }, function() {

View File

@ -0,0 +1,3 @@
<div id='simple-container'>
<div class='account-created'>{{{accountCreated.message}}}</div>
</div>

View File

@ -7,4 +7,9 @@
padding: 20px;
width: 550px;
margin: 0 auto;
.account-created {
font-size: 16px;
line-height: 24px;
}
}

View File

@ -10,6 +10,7 @@ require_dependency 'letter_avatar'
require_dependency 'distributed_cache'
require_dependency 'global_path'
require_dependency 'secure_session'
require_dependency 'topic_query'
class ApplicationController < ActionController::Base
include CurrentUser

View File

@ -534,8 +534,10 @@ class UsersController < ApplicationController
def account_created
@custom_body_class = "static-account-created"
@message = session['user_created_message'] || I18n.t('activation.missing_session')
store_preloaded("accountCreated", MultiJson.dump(message: @message))
expires_now
render layout: 'no_ember'
render "default/empty"
end
def activate_account

View File

@ -1,9 +0,0 @@
<div id='simple-container'>
<span style="font-size: 16px; line-height: 24px;"><%= @message.html_safe %></span>
</div>
<%- content_for(:no_ember_head) do %>
<%= render_google_universal_analytics_code %>
<%- end %>
<%= render_google_analytics_code %>

View File

@ -0,0 +1,17 @@
import { acceptance } from "helpers/qunit-helpers";
import PreloadStore from 'preload-store';
acceptance("Account Created");
test("account created", () => {
visit("/u/account-created");
PreloadStore.store('accountCreated', {
message: "Hello World"
});
andThen(() => {
ok(exists('.account-created'));
equal(find('.account-created').text(), "Hello World", "it displays the message");
});
});