Commit 157835d1 authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Fix registration/activation/password bug, PLEASE ADJUST YOUR vispa.ini FILE.

parent d8e79061
[database]
#sqlalchemy.url = sqlite:////var/db/vispa.db
#sqlalchemy.url = sqlite:////var/vispa.db
[alembic]
use_alembic = True
# inplace installation
# path to migration scripts
script_location = vispa/models/alembic
# global installation
#script_location = vispa:models/alembic
auto_migrate = True
[web]
dev_mode = True
# use base when running in subdirectory
#base = /vispa
base = /vispa
# set dynamic part seperatly
#base_dynamic = /vispa
#base_static = http://localhost:8080/
#base.dynamic = /vispa
#base.static = http://localhost:8080/
# logging on client side
logging.level = all
......@@ -26,12 +25,30 @@ logging.ignore = []
text.welcome = Welcome to VISPA!
#text.login = Information for Login
#text.registration = Information for Registration
#text.forgot = Check your spam folder and uncheck no-reply@vispa.physik.rwth-aachen.de
use_forgot = False
#text.forgot = Information for Forgot password
# leave the feedback address empty to disable feedback
#feedback.address =
feedback.subject = VISPA Feedback
# user registration
# use $username and $userid variables
#registration.hook = ['useradd', '$username']
registration.autoactive = True
registration.mail_hosts = []
registration.sendmail = False
registration.subject = Your registration at VISPA
# retrieval of forgotten passwords
forgot.use = False
forgot.subject = Your VISPA password
# absolute url
password_url = http://localhost:4282/vispa/password
[websockets]
enabled = False
enabled = True
[executable]
......@@ -46,32 +63,19 @@ post_command_options = -p
[BatchSystem]
# BatchSystem used for submission of jobs
manager = local
#manager = condor
[workspace]
add = True
alter = True
# define default workspace id to use.
#default_workspace_id = 1
[user]
workspaces.add = True
workspaces.alter = True
# user registration
# use $username and $userid variables
#registration.hook = ['useradd', '$username']
registration.autoactive = True
registration.mail_hosts = []
registration.sendmail = False
registration.activation = http://localhost/activate
registration.forgot = http://localhost/forgot
registration.smpt_host = localhost
#registration.smpt_port = 25
[mail]
# if sender_address is not set, there is no mail functionality
sender_address = vispa@domain.tld
smtp.host = 127.0.0.1
smtp.port = 25
[extensions]
ignore = dummy
ignore = [dummy]
......@@ -108,8 +108,9 @@ class RootController(AbstractController):
workspace_ids = JSON.dumps(workspace_ids)
workspace_data = self.workspace_data()
workspace_data = JSON.dumps(workspace_data)
add_workspaces = vispa.config("user", "workspaces.add", True)
alter_workspaces = vispa.config("user", "workspaces.alter", True)
add_workspaces = vispa.config("workspace", "add", True)
alter_workspaces = vispa.config("workspace", "alter", True)
use_feedback = vispa.config("web", "feedback.address", "") != ""
data = {
"dev_mode" : dev_mode,
"username" : username,
......@@ -121,6 +122,7 @@ class RootController(AbstractController):
"add_workspaces" : add_workspaces,
"alter_workspaces" : alter_workspaces,
"log_level" : client_log_level,
"use_feedback" : use_feedback
}
data.update(preferences)
return data
......@@ -135,7 +137,7 @@ class RootController(AbstractController):
login_text = vispa.config("web", "text.login", "")
registration_text = vispa.config("web", "text.registration", "")
forgot_text = vispa.config("web", "text.forgot", "")
use_forgot = vispa.config("web", "use_forgot", False)
use_forgot = vispa.config("web", "forgot.use", False)
return {
"requested_path" : path,
"welcome_phrase" : welcome_phrase,
......
......@@ -144,7 +144,7 @@ class User(Base):
hash=User.generate_hash(32), status=User.INACTIVE)
# auto activate user?
autoactive = vispa.config('user', 'registration.autoactive', True)
autoactive = vispa.config("web", 'registration.autoactive', True)
if autoactive:
user.status = User.ACTIVE
......@@ -165,6 +165,9 @@ class User(Base):
raise MessageException("Invalid hash")
user.hash = None
user.password = sha256_crypt.encrypt(password)
if user.status == User.INACTIVE:
user.status = User.ACTIVE
vispa.fire_callback("user.activate", user)
vispa.fire_callback("user.set_password", user)
......@@ -173,13 +176,13 @@ class User(Base):
@staticmethod
def send_registration_mail(name, email, hash):
# create the mail content
from_addr = "do-not-reply@vispa.physik.rwth-aachen.de"
to_addr = email
subject = "Your Vispa Registration"
subject = vispa.config("web", "registration.subject",
"Your registration at VISPA")
url = vispa.config("web", "password_url",
"http://localhost:4282/vispa/password")
response_host = vispa.config('user', 'registration.activation', 'http://localhost/password')
link = os.path.join(response_host, hash)
msg = """Thanks for your registration, %s!
link = os.path.join(url, hash)
content = """Thanks for your registration, %s!
\n\n
To finish your registration, click on the link below:
\n\n
......@@ -187,40 +190,26 @@ class User(Base):
\n\n
Your Vispa-Team!""" % (name, link)
User.send_mail(from_addr, to_addr, subject, msg)
@staticmethod
def send_mail(from_addr, to_addr, subject="", content=""):
smtp_host = vispa.config('user', 'registration.smtp_host', '127.0.0.1')
smtp_port = vispa.config('user', 'registration.smtp_port', 25)
server = smtplib.SMTP(smtp_host, smtp_port)
head = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (from_addr, to_addr, subject)
server.sendmail(from_addr, to_addr, head + content)
vispa.send_mail(email, subject, content)
@staticmethod
def forgot_password(db, name_or_mail):
user = User.get_by_name(db, name_or_mail)
if not isinstance(user, User):
user = User.get_by_email(db, name_or_mail.lower())
if not user:
return False
elif user.status == User.INACTIVE:
user.send_registration_mail(user.name, user.email, user.hash)
if not user or user.status == User.INACTIVE:
return False
hash = User.generate_hash(32)
user.hash = hash
# create the mail content
from_addr = "do-not-reply@vispa.physik.rwth-aachen.de"
to_addr = user.email
subject = "Your Vispa Password"
subject = vispa.config("web", "forgot.subject", "Your VISPA password")
url = vispa.config("web", "password_url",
"http://localhost:4282/vispa/password")
response_host = vispa.config('user', 'registration.forgot', 'http://localhost/password')
link = os.path.join(response_host, hash)
msg = """Hi %s!
link = os.path.join(url, hash)
content = """Hi %s!
\n\n
You requested a password change. To set a new one, click on the link below:
\n\n
......@@ -228,23 +217,9 @@ class User(Base):
\n\n
Your Vispa-Team!""" % (user.name, link)
try:
User.send_mail(from_addr, to_addr, subject, msg)
except:
pass
vispa.send_mail(user.email, subject, content)
return link
@staticmethod
def activate(session, hash):
user = User.get_by_hash(session, hash)
if not isinstance(user, User):
return False
if User.is_active(session, user.id):
return False
user.status = User.ACTIVE
vispa.fire_callback("user.activate", user)
return user
@staticmethod
def generate_hash(length=10):
chars = "abcdefghijklmnopqrstuvwxyz"
......
......@@ -57,4 +57,9 @@ form {
#forgot-name {
margin: 20px 0px;
}
input[type="checkbox"] {
margin-left: 0px !important;
margin-right: 6px !important;
}
\ No newline at end of file
......@@ -240,6 +240,10 @@ var Vispa = Emitter.extend({
self.preferenceView.show();
event.preventDefault();
});
$(".vispa-nav #feedback-button").click(function(event) {
self.showFeedbackDialog();
event.preventDefault();
});
return this;
},
......@@ -325,6 +329,45 @@ var Vispa = Emitter.extend({
});
});
return target;
},
showFeedbackDialog: function() {
var send = function(content) {
if (!content)
return;
$.post(vispa.url.dynamic("ajax/feedback"), {content: content});
};
var dfds = [
this.getTemplate("html/index/feedback/body.html"),
this.getTemplate("html/index/feedback/footer.html")
];
$.when.apply($, dfds).then(function(bodyTmpl, footerTmpl) {
var $body = $(bodyTmpl);
var $footer = $(footerTmpl);
vispa.messenger.dialog({
header: "<i class='glyphicon glyphicon-comment'></i> Feedback",
body: $body,
footer: $footer,
wrapFooter: false,
onShow: function() {
var dialog = this;
// cancel
$footer.find("button#cancel").click(this.close.bind(this))
// send
$footer.find("button#send").click(function() {
send($body.find("textarea").val());
dialog.close();
});
$body.find("textarea").focus();
}
});
});
return this;
}
});
......
......@@ -88,6 +88,12 @@ var Vispa = Class.extend({
.done(function(response) {
if (response.hash)
window.location.href = self.url.dynamic("password/" + response.hash);
else {
$("#register-success").fadeIn(100);
setTimeout(function() {
window.location.href = self.url.dynamic("/");
}, 4000);
}
}).fail(function(response, status, message) {
$("#register-alert").fadeIn(100).render({alert: response.responseText || message});
$("#register-name").focus();
......@@ -111,7 +117,7 @@ var Vispa = Class.extend({
$.post(this.url.dynamic("ajax/forgotpassword"), {username: user})
.done(function(response) {
$("#forgot-alert2").fadeIn(100);
$("#forgot-success").fadeIn(100);
setTimeout(function() {
window.location.href = self.url.dynamic("/");
}, 4000);
......
......@@ -47,7 +47,7 @@ var Vispa = Class.extend({
}
if (pass1 != pass2) {
bootbox.alert("Your passwords don't match!");
Dialog.alert("Your passwords don't match!");
return this;
}
......@@ -58,7 +58,7 @@ var Vispa = Class.extend({
$.cookie("tmpPass", pass1, { expires: d });
window.location.href = self.url.dynamic("/");
}).fail(function(response, status, message) {
bootbox.alert(response.responseText || message);
Dialog.alert(response.responseText || message);
});
return this;
......
......@@ -152,6 +152,10 @@
<i class="glyphicon glyphicon-warning-sign"></i>
<span data-bind="alert"></span>
</div>
<div class="alert alert-success" id="register-success" style="display:none;">
<i class="glyphicon glyphicon-ok"></i>
<span>Further instructions have been sent to your mail address! Redirecting in 4 seconds ...</span>
</div>
</div>
<div class="col-md-6 col-md-offset-1">
<div class="side_text">
......@@ -181,8 +185,8 @@
<i class="glyphicon glyphicon-warning-sign"></i>
<span data-bind="alert"></span>
</div>
<div class="alert alert-success" id="forgot-alert2" style="display:none;">
<i class="glyphicon glyphicon-warning-sign"></i>
<div class="alert alert-success" id="forgot-success" style="display:none;">
<i class="glyphicon glyphicon-ok"></i>
<span>Further instructions have been sent to your mail address! Redirecting in 4 seconds ...</span>
</div>
</div>
......
......@@ -25,11 +25,19 @@
"jquery/mobile/jquery.mobile.custom.min.js",
"bootstrap/js/bootstrap.min.js",
"bootstrap/select/bootstrap-select.min.js",
"bootstrap/slider/bootstrap-slider.min.js"
"bootstrap/slider/bootstrap-slider.min.js",
"class/class.js",
"node/eventemitter.min.js"
]
vispa_files = [
"base/emitter.js",
"base/dialog.js"
]
for file in vendor_files:
base.import_js(url.static("vendor/" + file))
for file in vispa_files:
base.import_js(url.static("js/" + file))
%>
</%block>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment