def on_post(self, req, resp): email = json.loads(req.stream.read())['email'] try: user = session.query(model.User).filter(model.User.email == email).first() except SQLAlchemyError: session.rollback() raise if not user: resp.status = falcon.HTTP_400 req.context['result'] = { 'result': 'error' } return new_password = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(8)) user.password = auth.get_hashed_password(new_password) try: session.add(user) session.commit() except SQLAlchemyError: session.rollback() raise try: util.mail.send(user.email, '[KSI] Nové heslo', u'Ahoj,<br/>na základě tvé žádosti ti bylo vygenerováno nové heslo: %s<br/><br/>KSI' % new_password) except SQLAlchemyError: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stderr) session.close() req.context['result'] = { 'result': 'ok' }
def on_post(self, req, resp): data = json.loads(req.stream.read()) try: existing_user = session.query(model.User).filter(model.User.email == data['email']).first() if existing_user != None: req.context['result'] = { 'error': "duplicate_user" } return except SQLAlchemyError: session.rollback() raise try: if not 'nick_name' in data: data['nick_name'] = "" user = model.User(email=data['email'], password=auth.get_hashed_password(data['password']), first_name=data['first_name'], last_name=data['last_name'], nick_name=data['nick_name'], sex=data['gender'], short_info=data["short_info"]) session.add(user) session.commit() except: session.rollback() req.context['result'] = { 'error': "Nelze vytvořit uživatele, kontaktuj prosím orga." } raise try: profile = model.Profile(user_id=user.id, addr_street=data['addr_street'], addr_city=data['addr_city'], addr_zip=data['addr_zip'], addr_country=data['addr_country'],\ school_name=data['school_name'], school_street=data['school_street'], school_city=data['school_city'], school_zip=data['school_zip'], school_country=data['school_country'], school_finish=int(data['school_finish']),\ tshirt_size=data['tshirt_size'].upper()) except: session.delete(user) req.context['result'] = { 'error': "Nelze vytvořit profil, kontaktuj prosím orga." } raise try: session.add(profile) session.commit() except: session.rollback() raise try: util.mail.send(user.email, u'[KSI-WEB] Potvrzení registrace do Korespondenčního semináře z informatiky', u'Ahoj!<br/>Vítáme tě v Korespondenčním semináři z informatiky Fakulty informatiky Masarykovy univerzity. Nyní můžeš začít řešit naplno. Stačí se přihlásit na https://ksi.fi.muni.cz pomocí e-mailu a zvoleného hesla. Přejeme ti hodně úspěchů při řešení semináře!<br/><br/>KSI') except: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stderr) session.close()
def on_post(self, req, resp): email = json.loads(req.stream.read().decode('utf-8'))['email'] try: user = session.query(model.User).\ filter(model.User.email == email).\ first() except SQLAlchemyError: session.rollback() raise if not user: resp.status = falcon.HTTP_400 req.context['result'] = {'result': 'error'} return new_password = ''.join( random.SystemRandom().choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(8)) user.password = auth.get_hashed_password(new_password) try: session.add(user) session.commit() except SQLAlchemyError: session.rollback() raise try: util.mail.send( user.email, '[KSI] Nové heslo', 'Ahoj,<br/>na základě tvé žádosti ti bylo vygenerováno nové ' 'heslo: %s<br/><br/>KSI' % new_password) except SQLAlchemyError: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stderr) session.close() req.context['result'] = {'result': 'ok'}
def update_user(user): old_user = get_user(user.id) if not auth.check_password(old_user, user.password_clear): raise Unauthorized("Users password does not match!") password_hash = old_user.pwd_salty_hash if not user.newPassword is None: password_hash = auth.get_hashed_password( user.newPassword.encode('utf-8')) with sql.connect(current_app.config['SQL_FILE']) as connection: cur = connection.cursor() val = (user.name, user.privilege, password_hash, user.id) cur.execute( '''UPDATE User SET name=?, privilege=?, password=? WHERE id=?''', val) connection.close()
def on_post(self, req, resp): user = req.context['user'] if not user.is_logged_in(): resp.status = falcon.HTTP_400 return try: user = session.query(model.User).get(user.id) except SQLAlchemyError: session.rollback() raise data = json.loads(req.stream.read().decode('utf-8')) if not auth.check_password(data['old_password'], user.password): resp.status = falcon.HTTP_401 req.context['result'] = {'result': 'error'} return if data['new_password'] != data['new_password2']: req.context['result'] = {'result': 'error'} return user.password = auth.get_hashed_password(data['new_password']) try: session.add(user) session.commit() except SQLAlchemyError: session.rollback() raise finally: session.close() req.context['result'] = {'result': 'ok'}
def on_post(self, req, resp): user = req.context['user'] if not user.is_logged_in(): resp.status = falcon.HTTP_400 return try: user = session.query(model.User).get(user.id) except SQLAlchemyError: session.rollback() raise data = json.loads(req.stream.read()) if not auth.check_password(data['old_password'], user.password): resp.status = falcon.HTTP_401 req.context['result'] = { 'result': 'error' } return if data['new_password'] != data['new_password2']: req.context['result'] = { 'result': 'error' } return user.password = auth.get_hashed_password(data['new_password']) try: session.add(user) session.commit() except SQLAlchemyError: session.rollback() raise finally: session.close() req.context['result'] = { 'result': 'ok' }
def on_post(self, req, resp): data = json.loads(req.stream.read().decode('utf-8')) try: existing_user = session.query(model.User).\ filter(model.User.email == data['email']).\ first() if existing_user is not None: req.context['result'] = {'error': "duplicate_user"} return except SQLAlchemyError: session.rollback() raise try: if 'nick_name' not in data: data['nick_name'] = "" user = model.User(email=data['email'], password=auth.get_hashed_password( data['password']), first_name=data['first_name'], last_name=data['last_name'], nick_name=data['nick_name'], sex=data['gender'], short_info=data["short_info"]) session.add(user) session.commit() except SQLAlchemyError: session.rollback() req.context['result'] = { 'error': "Nelze vytvořit uživatele, kontaktuj prosím orga." } raise try: profile = model.Profile( user_id=user.id, addr_street=data['addr_street'], addr_city=data['addr_city'], addr_zip=data['addr_zip'], addr_country=data['addr_country'].lower(), school_name=data['school_name'], school_street=data['school_street'], school_city=data['school_city'], school_zip=data['school_zip'], school_country=data['school_country'].lower(), school_finish=int(data['school_finish']), tshirt_size=data['tshirt_size'].upper(), referral=data.get('referral', "{}")) except BaseException: session.delete(user) session.commit() req.context['result'] = { 'error': "Nelze vytvořit profil, kontaktuj prosím orga." } raise try: session.add(profile) session.commit() except SQLAlchemyError: session.rollback() raise try: notify = model.UserNotify( user=user.id, auth_token=util.user_notify.new_token(), notify_eval=data['notify_eval'] if 'notify_eval' in data else True, notify_response=data['notify_response'] if 'notify_response' in data else True, notify_ksi=data['notify_ksi'] if 'notify_ksi' in data else True, notify_events=data['notify_events'] if 'notify_events' in data else True, ) except BaseException: session.delete(profile) session.commit() session.delete(user) session.commit() req.context['result'] = { 'error': "Nelze vytvořit notifikační záznam, kontaktuj prosím orga." } raise try: session.add(notify) session.commit() except SQLAlchemyError: session.rollback() raise try: util.mail.send( user.email, '[KSI-WEB] Potvrzení registrace do Korespondenčního semináře ' 'z informatiky', 'Ahoj!<br/>Vítáme tě v Korespondenčním ' 'semináři z informatiky Fakulty informatiky Masarykovy ' 'univerzity. Nyní můžeš začít řešit naplno. Stačí se přihlásit' ' na https://ksi.fi.muni.cz pomocí e-mailu a zvoleného hesla. ' 'Přejeme ti hodně úspěchů při řešení semináře!<br/><br/>KSI') except SQLAlchemyError: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stderr) session.close() req.context['result'] = {}