def doMerge(email=None, key=None): """ Merge two accounts together. Will send a confirmation mail to the to-be-merged email. """ tmpl = lookup.get_template('profile.html') errors = '' if key is not None and isValidMergeUrlKey(key): newMail = getUserFromPassword(key[:8]) oldMail = getUserFromPassword(key[8:]) log.info('valid merging key, merging "' + newMail + '" and "' + oldMail + '" now') if mergeUser(newMail, oldMail): tmpl = lookup.get_template('index.html') return tmpl.render(good_news='Merge was successful!') else: log.warning('couldn\'t merge "' + newMail + '" and "' + oldMail + '" for some unexpected reason') return tmpl.render(feedback='Oh no! Something went wrong. Please try again later.' ) elif email is not None: log.info('merge "' + email.lower() + '" with "' + getCurrentUserName() + '"') if emailRegex.match(email) == None: errors += '<li>Your email is invalid</li>' elif not userExists(email, True): errors += '<li>' + str(email.lower()) \ + ' doesn\'t exist</li>' if userExists(getCurrentUserName()): events = listAllEventsFor(getCurrentUserName()) for event in events: if str(event.participants).find(email) != -1: log.info('found instance where "' + email.lower() + '" and "' + getCurrentUserName().lower() + '" are listed as hoster and participant. Can\'t merge' ) errors = \ '<li>Can\'t merge these two accounts, because there are events, where host and participant are the same person.</li>' if str(event.owner).find(email) != -1: log.info('found instance where owner and to-be-merged user are the same' ) errors = '<li>Can\'t merge two same accounts.</li>' if not errors == '': return tmpl.render(bad_news='<ul>' + errors + '</ul>') else: mergeKey = getMergeUrlKey(getCurrentUserName(), email) Email.mergeRequest(getCurrentUserName(), email, mergeKey) return tmpl.render(good_news='An email has be sent to "' + email.lower() + '" for further information') else: tmpl = lookup.get_template('index.html') return tmpl.render(bad_news="Something went wrong, merge wasn't successful (maybe you already merged?)" )
def doResend(email): log.info("do a resend request for '" + str(email) + "'") if email is None or not emailRegex.match(email) \ or not db.userExists(email, True): tmpl = lookup.get_template('resend.html') return tmpl.render(bad_news='we could not find your email', email=email) Email.sendInvitationMail(email, db.getResetUrlKey(email)) tmpl = lookup.get_template('register.html') return tmpl.render(good_news='We resent your invitation code :)', email=email)
def doRemoveAlias(email): """ Removes an alias from the current user """ tmpl = lookup.get_template('profile.html') log.info('remove alias ' + email.lower()) if not emailRegex.match(email): return tmpl.render(bad_news='The given email is invalid') removeAlias(getCurrentUserName(), email) raise cherrypy.HTTPRedirect(cherrypy.url('profile#alias'))
def doRegister( email=None, key=None, nick=None, pwd1=None, pwd2=None, ): """ Processes a register-request: checks email & pwd & if user exists. Sends activation email, if successfull. """ log.info('register ' + str(email) + ' (' + str(nick) + ')') tmpl = lookup.get_template('register.html') errors = '' escapeRegex = False # Quick checking some values against the DB if email is None: errors += '<li>You have to provide an email address</li>' if key is None: errors += \ "<li>You have to provide a registration key(<a href='resend?email=" \ + str(email) + "'>resend</a>)</li>" if emailRegex.match(email) == None: errors += '<li>Your email is invalid</li>' escapeRegex = True if not escapeRegex and not db.isValidResetUrlKey(email, key, True): errors += \ "<li>The registration key is invalid. You have to enter the same emailadress you've been invited to.(<a href='resend?email=" \ + str(email) + "'>resend</a>)</li>" if nick is None or str(nick).__len__() < 3: errors += \ '<li>Please enter a nick, with a minimum length of 3</li>' if str(pwd1).__len__() < 6: errors += '<li>Your password is too short</li>' if not pwd1 == pwd2: errors += '<li>Passwort repetion incorrect</li>' if not escapeRegex and db.userExists(email, False): errors += '<li>User already exists</li>' if not errors == '': return tmpl.render(bad_news='<ul>' + errors + '</ul>', givenKey=key, givenEmail=email) else: if db.activateUser(email, nick, pwd1, True): Email.signupConfirm(email) return tmpl.render(good_news="You'll hear from us - check your mailbox" ) else: return tmpl.render(bad_news='Something went wrong. Please try again later' )
def forgot_reenter(email=None, resetKey=None): """ Processes the confirmed reset of a pwd (user clicke on link in email). Generates new password and sends it via mail """ log.info('forgot ' + email + ', key ' + resetKey) tmpl = lookup.get_template('forgot_pwd_reenter.html') if not emailRegex.match(email): return tmpl.render(bad_news='your email is invalid') if activatenCode.match(resetKey) and db.isValidResetUrlKey(email, resetKey): return tmpl.render(good_news='Choose your new password.', email=email, resetKey=resetKey) else: return tmpl.render(bad_news="Your reset key is invalid :'-(")
def forgot_doReenter( email=None, resetKey=None, pwd1=None, pwd2=None, ): tmpl = lookup.get_template('forgot_pwd_reenter.html') if not emailRegex.match(email): return tmpl.render(bad_news='Your email is invalid.', resetKey=resetKey, email=email) if email is None: return tmpl.render(bad_news='please enter your emai!', resetKey=resetKey) if pwd1 is None: return tmpl.render(bad_news='please enter a password!', resetKey=resetKey, email=email) if pwd1 != pwd2: return tmpl.render(bad_news='you have to enter the same password twice ;)' , resetKey=resetKey, email=email) if resetKey is None: return tmpl.render(bad_news='You have to enter a reset key') if str(pwd1).__len__() < 6: return tmpl.render(bad_news='your password is too short', resetKey=resetKey, email=email) if not activatenCode.match(resetKey) \ or not db.isValidResetUrlKey(email, resetKey): return tmpl.render(good_news='Your reset key is invalid or has expired.' , resetKey=resetKey, email=email) db.updateLogin(email, pwd1) return tmpl.render(good_news="You'r password has been set successfully" )
def doAddAlias(alias=None, mainMail=None, key=None): """ Add an alias to this account. """ tmpl = lookup.get_template('profile.html') errors = '' if key is not None and isValidAliasUrlKey(key): mainMail = getUserFromPassword(key[:8]) alias = getUserFromPassword(key[8:]) log.info('valid alias key, add "' + alias + '" as alias to "' + mainMail) if mergeUser(mainMail, alias): return tmpl.render(good_news='Your alias has been added') else: log.warning('couldn\'t alias/merge "' + currentUser + '" and "' + oldUser + '" for some unexpected reason') return tmpl.render(bad_news='Oh no! Something went wrong. Please try again later.' ) elif alias is not None: log.info('alias is not not') alias = [x.strip() for x in alias.split(',')] for user in alias: if emailRegex.match(user) == None: errors += '<li>' + user + ' is invalid</li>' else: if userExists(user, True): errors += '<li>' + user \ + ' already exists, use <a href="../merge">Merge E-Mails</a> instead</li>' elif aliasUserExists(user): errors += '<li>' + user \ + ' is already an alias for someone else</li>' if not errors == '': return tmpl.render(bad_news='<ul>' + errors + '</ul>') else: info = '' for user in alias: if activateUser(user, 'Alias for ' + user, 'random', True): log.info('register ' + user + ' for the purpose of adding as alias') aliasKey = getMergeUrlKey(getCurrentUserName(), user) Email.aliasRequest(getCurrentUserName(), user, aliasKey) info += '<li>An email has been sent to "' \ + user.lower() \ + '" for further information</li>' return tmpl.render(good_news=info) else: return tmpl.render(good_news='Nothing to add to aliases list')