Beispiel #1
0
def sign_in():
    '''
    @@ Success sign in flash
    
    When the page redirected from sign up page,
    It display flash message.    
    '''
        
    """ main page before sign in"""
    error = None
    if request.method == 'POST':       
        error = check_user_info(request.form)
                    
    isLogin = len(session._get_current_object())
    if isLogin:
        isLogin = session[SessionResources().const.MEMBER_ID_INDEX]
        memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]
    else:
        memberIdIndex = None
        
    return render_template(HTMLResources().const.MAIN_HTML,
                           noticeRecords = select_notices(memberIdIndex,
                                                          isLogin),
                           topCoders = select_top_coder(),
                           error = error)
def unknown_error(error = get_message()):
    from GradeServer.utils.utilArticleQuery import select_notices
    from GradeServer.utils.utilRankQuery import select_top_coder
    
    return render_template(HTMLResources().const.MAIN_HTML,
                           SessionResources = SessionResources,
                           SETResources = SETResources,
                           LanguageResources = LanguageResources,
                           notices = select_notices (),
                           topCoderId = select_top_coder (),
                           error = error)
def unknown_error(error=None):
    from GradeServer.utils.utilArticleQuery import select_notices
    from GradeServer.utils.utilRankQuery import select_top_coder

    from GradeServer.resource.htmlResources import HTMLResources
    from GradeServer.resource.sessionResources import SessionResources

    #from GradeServer.GradeServer_logger import Log

    isLogin = len(session._get_current_object())
    if isLogin:
        isLogin = session[SessionResources().const.MEMBER_ID_INDEX]
        memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]
    else:
        memberIdIndex = None

    return render_template(HTMLResources().const.MAIN_HTML,
                           noticeRecords=select_notices(
                               memberIdIndex, isLogin),
                           topCoders=select_top_coder(),
                           error=error)
def unknown_error(error = None):    
    from GradeServer.utils.utilArticleQuery import select_notices
    from GradeServer.utils.utilRankQuery import select_top_coder
    
    from GradeServer.resource.htmlResources import HTMLResources
    from GradeServer.resource.sessionResources import SessionResources
    
    #from GradeServer.GradeServer_logger import Log
    
    isLogin = len(session._get_current_object())
    if isLogin:
        isLogin = session[SessionResources().const.MEMBER_ID_INDEX]
        memberIdIndex = session[SessionResources().const.MEMBER_ID_INDEX]
    else:
        memberIdIndex = None
        
    return render_template(HTMLResources().const.MAIN_HTML,
                           noticeRecords = select_notices(memberIdIndex,
                                                          isLogin),
                           topCoders = select_top_coder(),
                           error = error)
def sign_in():
    '''
    @@ Success sign in flash
    
    When the page redirected from sign up page,
    It display flash message.    
    '''
    if '?' in request.url:
        flash('Signed up successfully')
        
    """ main page before sign in"""
    from GradeServer.utils.utilMessages import get_message
    
    from GradeServer.utils.memberCourseProblemParameter import MemberCourseProblemParameter
    
    from GradeServer.utils.utilArticleQuery import select_notices
    from GradeServer.utils.utilUserQuery import select_match_member
    from GradeServer.utils.utilRankQuery import select_top_coder
    
    from GradeServer.resource.htmlResources import HTMLResources
    from GradeServer.resource.sessionResources import SessionResources

    error = None
    if request.method == 'POST':
        checker = True
        language = {'kr':0, # default
                    'en':1}
        
        for form in request.form:
            if "language" in form:
                checker = False
                lang = request.form['language']
                session['language'] = language[lang]
                
        if checker:        
            if not request.form['memberId']:
                error = '아이디'  + get_message('fillData')
            elif not request.form['password']:
                error = '암호'  + get_message('fillData')
            else:
                try:
                    """ DB Password check """
                    memberId = request.form['memberId'].split()[0]
                    password = request.form['password']
                    
                    check = select_match_member(memberCourseProblemParameter = MemberCourseProblemParameter(memberId = memberId)).first()
                    
                    from werkzeug.security import check_password_hash
                    
                    from GradeServer.GradeServer_py3des import TripleDES
                    
                    #Checking Success
                    if check_password_hash (check.password,
                                            TripleDES.encrypt(str(password))):
                        flash(get_message('login'))
                        #push Session Cache 
                        session[SessionResources().const.MEMBER_ID] = memberId
                        session[SessionResources().const.MEMBER_NAME] = check.memberName
                        session[SessionResources().const.AUTHORITY] = list(check.authority)
                        session[SessionResources().const.LAST_ACCESS_DATE] = datetime.now()
                        
                        # set default language
                        session['language'] = language['kr']
                                                    
                        update_recent_access_date(memberId)
                        # Commit Exception
                        try:
                            dao.commit()
                        except Exception:
                            dao.rollback()
                            error = get_message('updateFailed')
                    else:
                        error = get_message('tryAgain')
                # Not Exist MemberId
                except Exception:
                    error = get_message('notExists')
        
    return render_template(HTMLResources().const.MAIN_HTML,
                           noticeRecords = select_notices(),
                           topCoderId = select_top_coder(),
                           error = error)
def sign_in():
    '''
    @@ Success sign in flash
    
    When the page redirected from sign up page,
    It display flash message.    
    '''
    if '?' in request.url:
        flash('Signed up successfully')
        
    ''' main page before sign in'''
    from GradeServer.utils.utilMessages import get_message
    
    from GradeServer.utils.memberCourseProblemParameter import MemberCourseProblemParameter
    
    from GradeServer.utils.utilArticleQuery import select_notices
    from GradeServer.utils.utilQuery import select_accept_courses, select_past_courses, select_current_courses, select_match_member
    from GradeServer.utils.utilRankQuery import select_top_coder
    
    from GradeServer.resource.setResources import SETResources
    from GradeServer.resource.htmlResources import HTMLResources
    from GradeServer.resource.sessionResources import SessionResources
    from GradeServer.resource.languageResources import LanguageResources

    error = None
    
    if request.method == 'POST':
        checker = True
        language = {'kr':0, # default
                    'en':1}
        
        for form in request.form:
            if "language" in form:
                checker = False
                lang = request.form['language']
                session['language'] = language[lang]
                
        if checker:        
            if not request.form['memberId']:
                error = '아이디'  + get_message('fillData')
            elif not request.form['password']:
                error = '암호'  + get_message('fillData')
            else:
                try:
                    """ DB Password check """
                    memberId = request.form['memberId'].split()[0]
                    password = request.form['password']
                    
                    check = select_match_member(memberCourseProblemParameter = MemberCourseProblemParameter(memberId = memberId)).first()
                    
                    from werkzeug.security import check_password_hash
                    
                    from GradeServer.resource.otherResources import OtherResources
                    from GradeServer.py3Des.pyDes import *
                    
                    tripleDes = triple_des(OtherResources().const.TRIPLE_DES_KEY,
                                           mode = ECB,
                                           IV = "\0\0\0\0\0\0\0\0",
                                           pad = None,
                                           padmode = PAD_PKCS5)
                    #Checking Success
                    if check_password_hash (check.password,
                                            tripleDes.encrypt(str(password))):
                        flash(get_message('login'))
                        #push Session Cache 
                        session[SessionResources().const.MEMBER_ID] = memberId
                        session[SessionResources().const.AUTHORITY] = list(check.authority)
                        session[SessionResources().const.LAST_ACCESS_DATE] = datetime.now()
                        
                        # set default language
                        session['language'] = language['kr']
                                                    
                        ownCourses = select_accept_courses().subquery()
                        # Get My Accept Courses
                        try:
                            session[SessionResources().const.OWN_CURRENT_COURSES] = select_current_courses(ownCourses).all()
                        except Exception:
                            session[SessionResources().const.OWN_CURRENT_COURSES] = []
                        try:
                            session[SessionResources().const.OWN_PAST_COURSES] = select_past_courses(ownCourses).all()
                        except Exception:
                            session[SessionResources().const.OWN_PAST_COURSES] = []
                        update_recent_access_date(memberId)
                        # Commit Exception
                        try:
                            dao.commit()
                        except Exception:
                            dao.rollback()
                            error = get_message('updateFailed')
                    else:
                        error = get_message('tryAgain')
                # Not Exist MemberId
                except Exception:
                    error = get_message('notExists')
            
    return render_template(HTMLResources().const.MAIN_HTML,
                           SETResources = SETResources,
                           SessionResources = SessionResources,
                           LanguageResources = LanguageResources,
                           noticeRecords = select_notices(),
                           topCoderId = select_top_coder(),
                           error = error)