def get_member_name(memberId):
    try:
        memberName = select_match_member(MemberCourseProblemParameter(memberId = memberId)).first().\
                                                                                            memberName
        return memberName
    except Exception as e:
        return unknown_error(get_message('dbError'))
Example #2
0
def id_check(select, error = None):
    if request.method == 'POST':
        # 암호를 입력 안했을 때
        if not request.form['password']:
            error ='Password' + get_message('fillData')
        else:
            try:
                memberId = session[SessionResources().const.MEMBER_ID]
                password = request.form['password']
                check = select_match_member(memberCourseProblemParameter = MemberCourseProblemParameter(memberId = memberId)).first()
                
                                # 암호가 일치 할 때
                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))):
                    # for all user
                    if select == 'account':
                        return redirect(url_for(RouteResources().const.EDIT_PERSONAL))
                    # server manager
                    elif SETResources().const.SERVER_ADMINISTRATOR in session[SessionResources().const.AUTHORITY][0]:
                        if select == 'server_manage_collegedepartment':
                            return redirect(url_for('.server_manage_collegedepartment'))
                        elif select == 'server_manage_class':
                            return redirect(url_for('.server_manage_class'))
                        elif select == 'server_manage_problem':
                            return redirect(url_for('.server_manage_problem'))
                        elif select == 'server_manage_user':
                            return redirect(url_for('.server_manage_user'))
                        elif select == 'server_manage_service':
                            return redirect(url_for('.server_manage_service'))
                    # class manager
                    elif SETResources().const.COURSE_ADMINISTRATOR in session[SessionResources().const.AUTHORITY][0]:
                        if select == 'user_submit':
                            return redirect(url_for('.class_user_submit'))
                        elif select == 'cm_manage_problem':
                            return redirect(url_for('.class_manage_problem'))
                        elif select == 'cm_manage_user':
                            return redirect(url_for('.class_manage_user'))
                        elif select == 'cm_manage_service':
                            return redirect(url_for('.class_manage_service'))
                    else:
                        return unknown_error()
                # 암호가 일치 하지 않을 때
                else:
                    error = get_message('wrongPassword')
            except Exception as e:
                Log.error(str(e))
                raise e
               
    return render_template(HTMLResources().const.ID_CHECK_HTML,
                           error = error)
Example #3
0
def check_invitee_member(inviteeId, teamName = None):
        # 인풋 폼안에 아이디가 있을 때
    if inviteeId:
        # 존재 하는 사용자 인지 확인
        if not dao.query(select_match_member(memberId = inviteeId).subquery()).\
                   first():
            
            return get_message('notExists')
        # 자가 자신 초대 방지
        elif inviteeId == session[SessionResources().const.MEMBER_ID]:
            return get_message('notSelf')
        # MakeTeam In Invitee
        elif not teamName:
                        # 초대 한 애를 또 초대 하는거를 방지
            if inviteeId in gTeamMembersId:
                return get_message('alreadyExists') 
            # Invitee Id Add
            gTeamMembersId.append(inviteeId)
            
            return None
        # ManageTeam In Invitee
        else:
                        # 초대 중복 방지
            if dao.query(TeamInvitations).\
                   filter(TeamInvitations.teamName == teamName,
                              TeamInvitations.inviteeId == inviteeId,
                              TeamInvitations.isDeleted == ENUMResources().const.FALSE).\
                   first():
                
                return get_message('alreadyExists')
            
                        # 팀원 초대 방지
            elif dao.query(RegisteredTeamMembers.teamMemberId).\
                     filter(RegisteredTeamMembers.teamName == teamName,
                            RegisteredTeamMembers.teamMemberId == inviteeId,
                            RegisteredTeamMembers.isDeleted == ENUMResources().const.FALSE).\
                     first():
                
                return get_message('notTeamMemberInvitee')
                        # 조건에 충족 될 때
            else:    
                return insert_invitee_id(teamName,
                                         inviteeId)
    # None 값 일 때
    else:
        return '아이디'  + get_message('fillData')
Example #4
0
def edit_personal(error = None):
    contactNumber, emailAddress, comment = None, None, None
    try:
        #Get User Information
        try:
            memberInformation = join_member_informations(select_match_member(memberCourseProblemParameter = MemberCourseProblemParameter(memberId = session[SessionResources().const.MEMBER_ID])).subquery()).first()
        except Exception:
            #None Type Exception
            memberInformation = []
        
        #Get Post
        if request.method == 'POST':
            password = request.form['password']
            passwordConfirm = request.form['passwordConfirm'] 
            #Get Updating Data
            contactNumber = request.form['contactNumber']
            emailAddress = request.form['emailAddress'] 
            comment = request.form['comment'] 
            #Password Same
            if(password and passwordConfirm) and password == passwordConfirm:
                #Generate Password
                tripleDes = triple_des(OtherResources().const.TRIPLE_DES_KEY,
                                       mode = ECB,
                                       IV = "\0\0\0\0\0\0\0\0",
                                       pad = None,
                                       padmode = PAD_PKCS5)
                
                # ID, Password NO
                if password == memberInformation.password\
                   or password == memberInformation.memberId:
                    error = get_message('pattenFailed')
                else:
                    
                    password = generate_password_hash(tripleDes.encrypt(str(password)))
                    passwordConfirm = None
                    #Update DB
                    update_member_informations(select_match_member(memberCourseProblemParameter = MemberCourseProblemParameter(memberId = session[SessionResources().const.MEMBER_ID])),
                                               password,
                                               contactNumber,
                                               emailAddress,
                                               comment)
                    # Commit Exception
                    try:
                        dao.commit()
                        flash(get_message('updateSucceeded'))
                        
                        return redirect(url_for(RouteResources().const.SIGN_IN))
                    except Exception:
                        dao.rollback()
                        error = get_message('upateFailed')
                
            #Password Different
            elif not password and not passwordConfirm:
                #Update DB
                update_member_informations(members = select_match_member(memberCourseProblemParameter = MemberCourseProblemParameter(memberId = session[SessionResources().const.MEMBER_ID])),
                                           password = None,
                                           contactNumber = contactNumber,
                                           emailAddress = emailAddress,
                                           comment = comment)
                # Commit Exception
                try:
                    dao.commit()
                    flash(get_message('updateSucceeded'))
                    
                    return redirect(url_for(RouteResources().const.SIGN_IN))
                except Exception:
                    dao.rollback()
                    error = get_message('upateFailed')
            else:
                error = get_message('wrongPassword')
        
        return render_template(HTMLResources().const.EDIT_PERSONAL_HTML,
                               memberInformation = memberInformation,
                               contactNumber = contactNumber,
                               emailAddress = emailAddress,
                               comment = comment,
                               error = error)
    except Exception:
        return unknown_error()
Example #5
0
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)