def request_reminder(self): """Checks that email exists, then send email to user with reset link """ logger.debug('requestReminder...') self._dbUser, self._dbSetting, self._dbUserMeta, self._dbMetaKey = self._instances(UserDAO, SettingDAO, UserMetaDAO, MetaKeyDAO) self._validate_email_exist() # Update User user = self._dbUser.get(email = self._f()['email']) days = self._get_setting(K.SET_REMINDER_DAYS).value new_date = date.today() + timedelta(days=int(days)) # Write reminderId and resetPasswordDate reminder_id = str(random.randint(1, 999999)) metas = self._dbMetaKey.metas([K.META_REMINDER_ID, K.META_RESET_PASSWORD_DATE]) self._dbUserMeta.save_meta(user, metas, { K.META_REMINDER_ID: reminder_id, K.META_RESET_PASSWORD_DATE: str(new_date)}) # Send email with link to reset password. Link has time validation xml_message = self._dbSetting.get(name__name='Msg/Site/Login/PasswordReminder/_en').value EmailService.send(xml_message, { 'home': settings.XIMPIA_HOME, 'appSlug': K.Slugs.SITE, 'viewSlug': K.Slugs.REMINDER_NEW_PASSWORD, 'firstName': user.first_name, 'userAccount': user.username, 'reminderId': reminder_id}, settings.XIMPIA_WEBMASTER_EMAIL, [self._f()['email']]) logger.debug('requestReminder :: sent Email') self._set_ok_msg('OK_PASSWORD_REMINDER')
def signup(self): """ Signup user **Attributes** **Returns** """ # Instances self._do_db_instances_for_user() # Business Validation self._validate_user_not_signed_up() self._validate_invitation_not_used() if self._f()['authSource'] != K.PASSWORD: self._create_user() # set ok message self._set_ok_msg('OK_SOCIAL_SIGNUP') else: # user/password. Save in temp table user data activation_code = random.randrange(10, 100) logger.debug('doUser :: activation_code: %s' % (activation_code)) form_serialized = base64.encodestring(self._f().serialize_JSON()) self._dbSignupData.delete_if_exists(user=self._f()['username'], is_real=True) self._dbSignupData.create(user=self._f()['username'], data=form_serialized, activationCode=activation_code) # Send email to user to validate email xml_message = self._dbSettings.get(name__name='Msg/Site/Signup/User/_en').value logger.debug(xml_message) logger.debug('path: %s' % (self._ctx.path)) EmailService.send(xml_message, {'scheme': settings.XIMPIA_SCHEME, 'host': settings.XIMPIA_BACKEND_HOST, 'appSlug': K.Slugs.SITE, 'activate': K.Slugs.ACTIVATE_USER, 'firstName': self._f()['firstName'], 'user': self._f()['username'], 'activationCode': activation_code}, settings.XIMPIA_WEBMASTER_EMAIL, [self._f()['email']]) # set ok message self._set_ok_msg('OK_USER_SIGNUP')