def unregist():
    user_id = session['user_info'].id
    
    try:
        user = dao.query(User).filter_by(id=user_id).first()
        Log.info("unregist:"+user.username)
        
        if user.id == user_id:
            dao.delete(user)
            # 업로드된 사진 파일 삭제
            try:
                upload_folder = \
                    os.path.join(current_app.root_path, 
                                 current_app.config['UPLOAD_FOLDER'])
                __delete_files(upload_folder, user.username)
            except Exception as e:
                Log.error("파일 삭제에 실패했습니다. : %s" + \
                          str(e))
            
            dao.commit()

        else:
            Log.error("존재하지 않는 사용자의 탈퇴시도 : %d", user_id)
            raise Exception

    except Exception as e:
        Log.error(str(e))
        dao.rollback()
        raise e
    
#     else:
    return redirect(url_for('.logout'))
def remove(locus_id):
    """ DB에서 해당 데이터를 삭제하고 관련된 이미지파일을 함께 삭제한다."""

    user_id = session['user_info'].id
    
    try:
        photo = dao.query(Photo).filter_by(id=str(locus_id)).first()
        
        dao.delete(photo)
        dao.commit()

        upload_folder = os.path.join(current_app.root_path, 
                                     current_app.config['UPLOAD_FOLDER'])
        os.remove(upload_folder + str(photo.filename))
        os.remove(upload_folder + "thumb_"+str(photo.filename))

    except Exception as e:
        dao.rollback()
        Log.error("Photo remove error => " + locus_id + ":" + user_id + \
                  ", " + str(e))
        raise e
    
    return redirect(url_for('.show_all'))