def check_code_token(): t=PTemplate(env) if yes_recovery_login==True: getpost=GetPostFiles() getpost.obtain_post() connection=WebModel.connection() user_admin=UserAdmin(connection) token=getpost.post.get('token', '') token=user_admin.fields['token_recovery'].check(token) if token.strip()!='': user_admin.set_conditions('WHERE token_recovery=%s', [token]) user_admin.yes_reset_conditions=False arr_user=user_admin.select_a_row_where(['id', 'email']) if arr_user: new_password=create_key() user_admin.valid_fields=['password', 'token_recovery', 'num_tries'] user_admin.reset_require() user_admin.check_user=False if user_admin.update({'password': new_password, 'token_recovery': "", 'num_tries': 0}, False): send_mail=SendMail() content_mail=t.load_template('admin/recovery_password.phtml', password=new_password) if not send_mail.send(email_address, [arr_user['email']], I18n.lang('admin', 'send_password_email', 'Your new password'), content_mail): return {'token': 'Error: i cannot send mail', 'error': 1} return {'token': 'Error: cannot send the maild with the new password', 'error': 0} s=get_session() s['csrf_token']=create_key_encrypt() s.save() return {'token': 'Error: token is not valid', 'error': 1, 'csrf_token': s['csrf_token']}
def send_password(): connection=WebModel.connection() user_admin=UserAdmin(connection) t=PTemplate(env) getpost=GetPostFiles() getpost.obtain_post() email=getpost.post.get('email', '') email=user_admin.fields['email'].check(email) if user_admin.fields['email'].error: s=get_session() s['csrf_token']=create_key_encrypt() s.save() return {'email': user_admin.fields['email'].txt_error, 'error': 1, 'csrf_token': s['csrf_token']} else: user_admin.set_conditions('WHERE email=%s', [email]) user_admin.yes_reset_conditions=False if user_admin.select_count()==1: user_admin.reset_require() user_admin.valid_fields=['token_recovery'] user_admin.check_user=False token=create_key_encrypt_256() if user_admin.update({'token_recovery': token}): send_mail=SendMail() content_mail=t.load_template('admin/recovery_mail.phtml', token=token) if not send_mail.send(email_address, [email], I18n.lang('admin', 'send_email', 'Email for recovery your password'), content_mail): return {'email': 'Error: i cannot send mail', 'error': 1} return {'email': '', 'error': 0}
timestamp_now = datetime.obtain_timestamp(now) five_minutes = int(timestamp_now) - 300 five_minutes_date = datetime.timestamp_to_datetime(five_minutes) server.set_conditions('WHERE date<%s', [five_minutes_date]) arr_server = [] with server.select(['hostname']) as cur: for s in cur: arr_server.append(s['hostname']) if len(arr_server) > 0: send_mail = SendMail() content_mail = "THE NEXT SERVERS ARE DOWN: " + ", ".join( arr_server) + "\n\n" content_mail = 'Please, click in this link for view the servers down; ' + config.domain_url + make_url( 'pastafari/servers', {'type': 'down'}) if not send_mail.send( email_address, config.email_notification, I18n.lang('pastafari', 'servers_down', 'WARNING: SERVERS ARE DOWN!'), content_mail): print('Sended email with notification')