def home_page(header, request): #raise() Setting.log.log_request(request) try: forgot_key = None #LogOut(header,request) init_db() user_name = "" authenticated = False session = request.session if 'authenticated' in session and session['authenticated']: authenticated = True uw = UserWorker() user_name = uw.get_user_full_name(session['username']) if 'forgotPasswordKey' in request.params.keys(): forgot_key = request.params.getone('forgotPasswordKey') nw = NewsWorker() news = nw.get_news() return { 'news': news, 'authenticated': authenticated, 'user_name': user_name, 'forgot_key': forgot_key } except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def home_page(header,request): #raise() Setting.log.log_request(request) try: forgot_key = None #LogOut(header,request) init_db() user_name = "" authenticated = False session = request.session if 'authenticated' in session and session['authenticated']: authenticated = True uw = UserWorker() user_name = uw.get_user_full_name(session['username']) if 'forgotPasswordKey' in request.params.keys(): forgot_key = request.params.getone('forgotPasswordKey') nw = NewsWorker() news = nw.get_news() return {'news':news,'authenticated':authenticated,'user_name':user_name,'forgot_key':forgot_key} except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def sign_up(request): try: success = False fail_type = '' if request.POST.has_key('username') and request.POST.has_key('password') : Setting.log.info("signup attemp for username:"******"signup done for email: username:"+request.POST['username']) else: fail_type = 'data' return {'success':success, 'fail_type': fail_type} except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def HomePage(header, request): print("ff") try: #LogOut(header,request) InitDB() user_name = "" authenticated = "false" session = request.session if 'authenticated' in session and session['authenticated']: authenticated = "true" uw = UserWorker() user_name = uw.GetUserFullName(session['username']) rr = RssReader() rr.Read() nw = NewsWorker() news = nw.GetNews() return { 'news': news, 'authenticated': authenticated, 'user_name': user_name } except Exception as ex: Setting.error_log.LogException(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def SignIn(request): try: success = False if request.POST.has_key('username') and request.POST.has_key( 'password'): Setting.log.info("login attemp for user:" + request.POST['username']) uw = UserWorker() InitDB() res = uw.SignIn(request.POST['username'], request.POST['password']) if res[0]: request.session['authenticated'] = True request.session['username'] = request.POST['username'] request.session['user_id'] = res[2] Setting.log.info('sign in done for ' + res[1] + ' and user id is ' + str(res[2])) return {'success': True, 'name': res[1]} return {'success': success} except Exception as ex: Setting.log.LogException(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def home_page(header,request): #raise() Setting.log.log_request(request) try: query = "" days = None source=None starred = None alert_message = "" if 'q' in request.params: query = request.params.getone('q') if 'date' in request.params: days = request.params.getone('date') if 'source' in request.params: source = request.params.getone('source') if 'starred' in request.params: tmp = request.params.getone('starred') if tmp == 'true': starred = True else: starred = False forgot_key = None #LogOut(header,request) init_db() user_name = "" authenticated = False session = request.session if 'authenticated' in session and session['authenticated']: authenticated = True uw = UserWorker() user_name = uw.get_user_full_name(session['username']) else: if len(query) > 0 or days != None or source != None: query = "" days = None source = None alert_message = u'تنها کاربران عضو قادر به جستجو می باشند'; if 'forgotPasswordKey' in request.params.keys(): forgot_key = request.params.getone('forgotPasswordKey') nw = NewsWorker() news = nw.get_news(query,source,days,starred,session['user_id'] if 'user_id' in session else None) sources = nw.get_all_sources() return {'news':news,'authenticated':authenticated,'user_name':user_name,'forgot_key':forgot_key, 'search_text':query,'search_source':source,'search_date':days,'alert_message':alert_message, 'sources':sources,'starred':'true' if starred== True else 'false'} except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def set_user_profile(request): try: init_db() u = UserWorker() res = u.set_user_profile(request.session['user_id'],request.POST['name'],request.POST['familly'], request.POST['mobile_number'],request.POST['password']) return {'success':res} except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def get_user_profile(request): try: init_db() u = UserWorker() info = u.get_user_profile(request.session['user_id']) return {'success':True , 'profile': {'name':info.name, 'familly':info.familly, 'mobile_number':info.mobile_number,'username':info.username}} except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def SignUp(header, request): try: success = False if request.POST.has_key('email') and request.POST.has_key( 'username') and request.POST.has_key('password'): uw = UserWorker() InitDB() if uw.SignUp(request.POST['email'], request.POST['username'], request.POST['password']): success = True return {'success': success} except Exception as ex: Setting.error_log.LogException(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def home_page(header, request): #raise() Setting.log.log_request(request) try: query = "" alert_message = "" if 'q' in request.params: query = request.params.getone('q') forgot_key = None #LogOut(header,request) init_db() user_name = "" authenticated = False session = request.session if 'authenticated' in session and session['authenticated']: authenticated = True uw = UserWorker() user_name = uw.get_user_full_name(session['username']) else: if len(query) > 0: query = "" alert_message = 'تنها کاربران عضو قادر به جستجو می باشند' if 'forgotPasswordKey' in request.params.keys(): forgot_key = request.params.getone('forgotPasswordKey') nw = NewsWorker() news = nw.get_news( query, session['user_id'] if 'user_id' in session else None) return { 'news': news, 'authenticated': authenticated, 'user_name': user_name, 'forgot_key': forgot_key, 'search_text': query, 'alert_message': alert_message } except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def home_page(header, request): # raise() Setting.log.log_request(request) try: query = "" alert_message = "" if "q" in request.params: query = request.params.getone("q") forgot_key = None # LogOut(header,request) init_db() user_name = "" authenticated = False session = request.session if "authenticated" in session and session["authenticated"]: authenticated = True uw = UserWorker() user_name = uw.get_user_full_name(session["username"]) else: if len(query) > 0: query = "" alert_message = "تنها کاربران عضو قادر به جستجو می باشند" if "forgotPasswordKey" in request.params.keys(): forgot_key = request.params.getone("forgotPasswordKey") nw = NewsWorker() news = nw.get_news(query) return { "news": news, "authenticated": authenticated, "user_name": user_name, "forgot_key": forgot_key, "search_text": query, "alert_message": alert_message, } except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response("sorry,problem")
def SignIn(header, request): try: success = False if request.POST.has_key('username') and request.POST.has_key( 'password'): uw = UserWorker() InitDB() res = uw.SignIn(request.POST['username'], request.POST['password']) if res[0]: request.session['authenticated'] = True request.session['username'] = request.POST['username'] return {'success': True, 'name': res[1]} return {'success': success} except Exception as ex: Setting.error_log.LogException(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def reset_password(request): try: success = False if request.POST.has_key('resetKey'): reset_key = request.POST['resetKey'] Setting.log.info("Reset password attemp for key:"+reset_key) uw = UserWorker() init_db() username = uw.find_username_by_reset_password_key(reset_key) email = uw.get_user_email(username) if email != "": Setting.log.info("Reset password attemp for user:"******"user password changed to "+new_password) (title, text, html) = get_reset_password_template() text = text.format(new_password) html = html.format(new_password) Setting.log.info("got template - title is "+title) sendmail(email, title, text, html) Setting.log.info("mail sent to "+email) success = True except Exception as ex: Setting.log.log_exception(ex) return { 'success': success}
def sign_in(request): try: success = False if request.POST.has_key('username') and request.POST.has_key('password') : Setting.log.info("login attemp for user:"+request.POST['username']) uw = UserWorker() init_db() res = uw.sign_in(request.POST['username'], request.POST['password']) if res[0] : request.session['authenticated'] = True request.session['username'] = request.POST['username'] request.session['user_id' ] = res[2] Setting.log.info('sign in done for '+res[1]+' and user id is '+str(res[2])) return {'success':True,'name':res[1]} return {'success':success} except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def home_page(header,request): #raise() Setting.log.log_request(request) try: query = "" alert_message = "" if 'q' in request.params: query = request.params.getone('q') forgot_key = None #LogOut(header,request) init_db() user_name = "" authenticated = False session = request.session if 'authenticated' in session and session['authenticated']: authenticated = True uw = UserWorker() user_name = uw.get_user_full_name(session['username']) else: if len(query) > 0 : query = "" alert_message = u'تنها کاربران عضو قادر به جستجو می باشند'; if 'forgotPasswordKey' in request.params.keys(): forgot_key = request.params.getone('forgotPasswordKey') nw = NewsWorker() news = nw.get_news(query,session['user_id'] if 'user_id' in session else None) return {'news':news,'authenticated':authenticated,'user_name':user_name,'forgot_key':forgot_key,'search_text':query,'alert_message':alert_message} except Exception as ex: Setting.log.log_exception(ex) if Setting.debuging: return Response(ex.__str__()) else: return Response('sorry,problem')
def forgot_password(request): try: success = False if request.POST.has_key('username'): username = request.POST['username'] Setting.log.info("Forgot password attemp for user:"******"": Setting.log.info("Forgot password attemp for user:"******"Forgot password attemp for user:"******"receiving email template") (title, text, html) = get_forgot_password_template() site_prefix = "www" if ( Setting.mode == "beta" ): site_prefix="beta" text = text.format("http://"+site_prefix+".yeksatr.com/?forgotPasswordKey="+reset_password_key) html = html.format("http://"+site_prefix+".yeksatr.com/?forgotPasswordKey="+reset_password_key) Setting.log.info("got template - title is "+title) sendmail(email, title, text, html) Setting.log.info("mail sent to "+email) except Exception as ex: Setting.log.log_exception(ex) return Response('')