Exemplo n.º 1
0
    def get(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        user_id = self.get_argument('user_id', '')

        ret = {}

        try:
            addresses = []

            session = Session()
            userdao = UserDAO()

            addresses = userdao.get_all_user_addresses(user_id)
            name = userdao.get_user_name(user_id)
            default_index = userdao.get_user_default_address_index(user_id)

            ret['response'] = {
                'name': name,
                'addresses': addresses,
                'user_id': user_id,
                'default_index': default_index
            }
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()
            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
Exemplo n.º 2
0
    def notify_10mins_ahead(self):
        try:
            userdao = UserDAO()

            current_time = dt.datetime.now()
            print '-' * 40
            print 'push before 10 minutes'
            print 'current_time :', current_time

            hour = current_time.hour
            if current_time.minute >= 20 and current_time.minute <= 29:
                minute = 30
            elif current_time.minute >= 50 and current_time.minute <= 59:
                hour += 1
                minute = 0
            else:
                minute = 0

            cron_time = current_time.replace(hour=hour,
                                             minute=minute,
                                             second=0,
                                             microsecond=0)

            print 'cron_time :', cron_time
            print '-' * 40

            session = Session()
            result = session.query(Booking, Master, User, UserPushKey) \
                            .join(Master, Booking.master_id == Master.id) \
                            .join(User, Booking.user_id == User.id) \
                            .outerjoin(UserPushKey, User.id == UserPushKey.user_id) \
                            .filter(or_(Booking.cleaning_status == BC.BOOKING_UPCOMMING, Booking.cleaning_status == BC.BOOKING_STARTED)) \
                            .filter(func.date(Booking.start_time) == cron_time.date()) \
                            .filter(func.HOUR(Booking.start_time) == cron_time.time().hour) \
                            .filter(func.MINUTE(Booking.start_time) == cron_time.time().minute) \
                            .all()

            for row in result:
                key = userdao.get_user_salt_by_id(row.User.id)[:16]
                crypto = aes.MyCrypto(key)

                booking_id = row.Booking.id
                pushkey = row.UserPushKey.pushkey if row.UserPushKey != None else ''
                user_name = crypto.decodeAES(row.User.name)
                phone = crypto.decodeAES(row.User.phone)
                master_name = row.Master.name
                devicetype = row.User.devicetype

                print 'push to', user_name, master_name, booking_id
                print pushkey

                if devicetype != 'android':
                    pushkey = crypto.decodeAES(row.User.phone)

                send_10mins_ahead_notification(devicetype, [pushkey],
                                               booking_id)
                send_alimtalk(phone, 'noti_10', user_name, master_name)

        except Exception, e:
            print_err_detail(e)
    def post(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        ret = {}

        user_id = self.get_argument('user_id', '')
        new_pwd = self.get_argument('new_pwd', 'hm123')

        try:
            userdao = UserDAO()
            session = Session()

            user_row = session.query(User).filter(User.id == user_id).one()

            salt = userdao.get_user_salt_by_id(user_id)
            hash_obj = hashlib.sha256(salt + new_pwd)

            user_row.password = hash_obj.hexdigest()
            session.commit()

            ret['response'] = Response.SUCCESS
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
    def get(self):
        ret = {}

        user_id         = self.get_argument('user_id', '')
        address_index   = self.get_argument('address_index', '')

        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        try:
            userdao = UserDAO()
            address, size, kind, rooms, baths = userdao.get_user_address_full_detail_by_index(user_id, address_index)

            address_info = {}
            address_info['rooms'] = rooms
            address_info['size'] = size
            address_info['kind'] = kind
            address_info['baths'] = baths
            address_info['address'] = address

            ret['response'] = address_info
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            add_err_message_to_response(ret, err_dict['err_mysql'])
            self.set_status(Response.RESULT_SERVERERROR)
            print_err_detail(e)
    def get(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        user_id = self.get_argument('user_id', '')
        havepet = self.get_argument('havepet', '')
        master_gender = self.get_argument('master_gender', '')

        havepet = int(havepet)
        master_gender = int(master_gender)

        ret = {}

        try:
            session = Session()
            userdao = UserDAO()
            addressdao = AddressDAO()

            masters = []

            row = session.query(UserDefaultAddress) \
                        .filter(UserDefaultAddress.user_id == user_id) \
                        .one()

            address, _, _ = userdao.get_user_address_by_index(
                user_id, row.address_idx)

            gu_id = addressdao.get_gu_id(address)

            pet_filter = 2
            if havepet == 1:
                pet_filter = 1

            gender_filter = 2
            if master_gender == 1:
                gender_filter = 0

            result = session.query(Master, MasterPreferedArea) \
                            .join(MasterPreferedArea, Master.id == MasterPreferedArea.master_id) \
                            .filter(Master.active == 1) \
                            .filter(Master.pet_alergy != pet_filter) \
                            .filter(Master.gender != gender_filter) \
                            .filter(MasterPreferedArea.prefered_gu == gu_id) \
                            .order_by(Master.name) \
                            .all()

            for row in result:
                masters.append({'id': row.Master.id, 'name': row.Master.name})

            ret['response'] = masters
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
    def notify(self):
        try:
            userdao = UserDAO()

            current_time = dt.datetime.now()

            print '-' * 40
            print 'push before 2 hours'
            print 'current_time :', current_time

            hour = current_time.hour
            minute = 30 if current_time.minute >= 30 else 0

            #current_time = current_time + dt.timedelta(hours=2)
            cron_time = current_time.replace(hour=hour+2, minute=minute, second = 0, microsecond=0)

            print 'cron_time :', cron_time
            print '-' * 40

            session = Session()
            result = session.query(Booking, Master, MasterPushKey, User) \
                            .join(Master, Booking.master_id == Master.id) \
                            .join(MasterPushKey, Master.id == MasterPushKey.master_id) \
                            .join(User, Booking.user_id == User.id) \
                            .filter(Booking.cleaning_status == BC.BOOKING_UPCOMMING) \
                            .filter(func.date(Booking.start_time) == cron_time.date()) \
                            .filter(func.HOUR(Booking.start_time) == cron_time.time().hour) \
                            .filter(func.MINUTE(Booking.start_time) == cron_time.time().minute) \
                            .all()


            for row in result:

                key = userdao.get_user_salt_by_id(row.User.id)[:16]
                crypto = aes.MyCrypto(key)

                if row.Master.id == 'da2a1f50-fd36-40bf-8460-55b3e1b2c459':
                    continue

                booking_id = row.Booking.id
                pushkey = row.MasterPushKey.pushkey if row.MasterPushKey != None else ''
                master_name = row.Master.name

                start_time = row.Booking.start_time
                time_str = convert_datetime_format4(start_time)

                print 'push to', master_name, booking_id
                print pushkey

                send_master_ahead_notification('android', [pushkey], booking_id, master_name, time_str)

        except Exception, e:
            print_err_detail(e)
Exemplo n.º 7
0
    def get(self):
        self.set_header("Content-Type", "application/json")

        ret = {}

        try:
            session = Session()

            ratings = []

            userdao = UserDAO()

            result = session.query(Rating, Booking, User, Master) \
                            .join(Booking, Rating.booking_id == Booking.id) \
                            .join(Master, Rating.master_id == Master.id) \
                            .join(User, Booking.user_id == User.id) \
                            .order_by(desc(Rating.review_time)) \
                            .all()

            for row in result:
                key = userdao.get_user_salt(row.User.email)[:16]
                crypto = aes.MyCrypto(key)

                rating = {}

                rating['user_name'] = crypto.decodeAES(row.User.name)
                rating['master_name'] = row.Master.name
                rating['appointment_type'] = row.Booking.appointment_type
                rating['start_time'] = dt.datetime.strftime(
                    row.Booking.start_time, '%Y-%m-%d %H:%M')
                rating['estimated_end_time'] = dt.datetime.strftime(
                    row.Booking.estimated_end_time, '%Y-%m-%d %H:%M')
                rating['end_time'] = dt.datetime.strftime(
                    row.Booking.end_time, '%Y-%m-%d %H:%M')
                rating['clean_rating'] = float(row.Rating.rate_clean)
                rating['clean_review'] = row.Rating.review_clean
                rating['master_rating'] = float(row.Rating.rate_master)
                rating['master_review'] = row.Rating.review_master
                rating['review_time'] = dt.datetime.strftime(
                    row.Rating.review_time, '%Y-%m-%d %H:%M')

                ratings.append(rating)

            ret['response'] = ratings
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
Exemplo n.º 8
0
    def get(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        ret = {}

        print "test-intro"

        try:
            session = Session()

            result = session.query(UserClaim, Booking, User, Master) \
                            .join(Booking, UserClaim.booking_id == Booking.id) \
                            .join(Master, Master.id == Booking.master_id) \
                            .join(User, User.id == Booking.user_id) \
                            .all()
            claims = []
            Userdao = UserDAO()

            print result

            for record in result:
                key = Userdao.get_user_salt(record.User.email)[:16]
                if key == None or key == '':
                    continue

                crypto = aes.MyCrypto(key)

                claim_info = {}
                claim_info['cleanning_date'] = dt.datetime.strftime(
                    record.Booking.start_time, '%Y-%m-%d %H:%M')
                claim_info['user_name'] = crypto.decodeAES(record.User.name)
                claim_info['user_phone'] = crypto.decodeAES(record.User.phone)
                claim_info['master_name'] = record.Master.name
                claim_info['claim_comment'] = record.UserClaim.comment
                claim_info['claim_reg_time'] = dt.datetime.strftime(
                    record.UserClaim.register_time, '%Y-%m-%d %H:%M')
                claims.append(claim_info)

            ret['response'] = claims
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
Exemplo n.º 9
0
    def get(self):
        self.set_header("Content-Type", "application/json")

        ret = {}

        master_id = self.get_argument('master_id', '')

        try:
            session = Session()
            userdao = UserDAO()

            result = session.query(Master, Booking, User) \
                            .join(Booking, Master.id == Booking.master_id) \
                            .join(User, Booking.user_id == User.id) \
                            .filter(Booking.master_id == master_id) \
                            .filter(or_(Booking.cleaning_status == BC.BOOKING_UPCOMMING, Booking.cleaning_status == BC.BOOKING_STARTED, Booking.cleaning_status == BC.BOOKING_COMPLETED)) \
                            .order_by(desc(Booking.start_time)) \
                            .all()

            booking_list = []

            for row in result:
                key = userdao.get_user_salt_by_id(row.Booking.user_id)[:16]
                crypto = aes.MyCrypto(key)

                booking = {}

                booking['booking_id'] = row.Booking.id
                booking['name'] = crypto.decodeAES(row.User.name)
                booking['start_time'] = convert_datetime_format2(
                    row.Booking.start_time)
                booking['additional_task'] = row.Booking.additional_task
                booking['price'] = row.Booking.price_with_task
                booking['status'] = row.Booking.status
                booking['cleaning_status'] = row.Booking.cleaning_status
                booking['payment_status'] = row.Booking.payment_status

                booking_list.append(booking)

            ret['response'] = booking_list
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
Exemplo n.º 10
0
    def get(self):
        self.set_header("Content-Type", "application/json")

        ret = {}

        try:
            session = Session()
            userdao = UserDAO()
            bookingdao = BookingDAO()

            # get last saturday
            now = dt.datetime.now()
            if week != 0:
                offset = ((now.weekday() - FRIDAY) % 7) + (week - 1) * 7
                now -= dt.timedelta(days=offset)

            offset = (now.weekday() - SATURDAY) % 7
            last_saturday = (now - dt.timedelta(days=offset)).date()
            now = now.date()

            # rating
            #

            ret['response'] = Response.SUCCESS
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
    def post(self):
        self.set_header("Content-Type", "application/json")

        booking_id = self.get_argument('booking_id', '')

        ret = {}

        try:
            session = Session()
            userdao = UserDAO()

            try:
                row = session.query(Booking).filter(
                    Booking.id == booking_id).one()
            except NoResultFound, e:
                session.close()
                self.set_status(Response.RESULT_OK)
                add_err_message_to_response(ret, err_dict['err_no_record'])
                return

            except MultipleResultsFound, e:
                session.close()
                self.set_status(Response.RESULT_OK)
                add_err_message_to_response(ret,
                                            err_dict['err_multiple_record'])
                return
Exemplo n.º 12
0
    def get(self):
        self.set_header("Content-Type", "application/json")

        manager_id = self.get_argument('manager_id', '')

        ret = {}

        try:
            session = Session()
            userdao = UserDAO()

            payment_records = []

            result = session.query(UserPaymentRecord, User) \
                            .join(User, UserPaymentRecord.user_id == User.id) \
                            .order_by(UserPaymentRecord.user_id, desc(UserPaymentRecord.auth_date)) \
                            .all()

            for row in result:
                payment = {}

                key = userdao.get_user_salt_by_id(row.User.id)[:16]
                crypto = aes.MyCrypto(key)

                payment['tid'] = row.UserPaymentRecord.tid
                payment['booking_id'] = row.UserPaymentRecord.booking_id
                payment['user_id'] = row.UserPaymentRecord.user_id
                payment['price'] = row.UserPaymentRecord.price
                payment['auth_date'] = row.UserPaymentRecord.auth_date
                payment[
                    'canceled_amount'] = row.UserPaymentRecord.canceled_amount
                payment['canceled_date'] = row.UserPaymentRecord.canceled_date
                payment['status'] = row.UserPaymentRecord.status
                payment['user_name'] = crypto.decodeAES(row.User.name)
                payment['user_phone'] = crypto.decodeAES(row.User.phone)

                payment_records.append(payment)

            ret['response'] = payment_records
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
    def post(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        phone = self.get_argument('phone', '')

        print 'phone', phone

        mongo_logger = get_mongo_logger()

        ret = {}

        try:
            session = Session()
            userdao = UserDAO()

            try:
                result = session.query(User) \
                            .filter(func.aes_decrypt(func.from_base64(User.phone), \
                            func.substr(User.salt, 1, 16)) == phone,  \
                            User.active == 1) \
                            .all()

            except NoResultFound, e:
                session.close()
                self.set_status(Response.RESULT_OK)
                add_err_message_to_response(ret,
                                            err_dict['err_login_no_match'])
                mongo_logger.error('%s failed to get registerinfo' % phone,
                                   extra={'err': str(e)})
                return

            usersinfo = []

            for row in result:
                userinfo = {}
                userinfo['id'] = row.id
                userinfo['name'] = userdao.get_user_name(row.id)
                userinfo['phone'] = userdao.get_user_phone(row.id)
                userinfo['email'] = row.email
                usersinfo.append(userinfo)

            mongo_logger.debug('user registered info')

            ret['response'] = usersinfo
            self.set_status(Response.RESULT_OK)
    def get(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        user_id = self.get_argument('user_id', '')

        ret = {}

        try:
            session = Session()
            userdao = UserDAO()

            payment_histories = []

            result = session.query(UserChargeRecord, User) \
                            .join(User, UserChargeRecord.user_id == User.id) \
                            .filter(UserChargeRecord.user_id == user_id) \
                            .order_by(desc(UserChargeRecord.auth_date)) \
                            .all()

            for row in result:
                try:
                    auth_date = '20' + row.UserChargeRecord.auth_date
                    auth_date = dt.datetime.strptime(auth_date, '%Y%m%d%H%M%S')
                except Exception, e:
                    auth_date = None

                payment_info = {}
                payment_info['tid'] = row.UserChargeRecord.tid
                payment_info['amount'] = row.UserChargeRecord.amount
                payment_info['auth_date'] = convert_datetime_format2(
                    auth_date) if auth_date != None else ''

                payment_histories.append(payment_info)

            user_name = userdao.get_user_name(user_id)
            user_phone = userdao.get_user_phone(user_id)

            ret['response'] = {
                'user_id': user_id,
                'name': user_name,
                'phone': user_phone,
                'payment_histories': payment_histories
            }
            self.set_status(Response.RESULT_OK)
    def get(self):
        self.set_header("Content-Type", "application/json")

        ret = {}

        try:
            session = Session()

            users = []

            userdao = UserDAO()

            for row in session.query(User, UserAddress) \
                            .outerjoin(UserDefaultAddress, UserDefaultAddress.user_id == User.id) \
                            .outerjoin(UserAddress, and_(UserDefaultAddress.user_id == UserAddress.user_id, UserDefaultAddress.address_idx == UserAddress.user_addr_index)) \
                            .order_by(desc(User.dateofreg)) \
                            .all():

                key = userdao.get_user_salt(row.User.email)[:16]
                crypto = aes.MyCrypto(key)

                user_info = {}
                user_info['user_id']    = row.User.id
                user_info['dateofreg']  = dt.datetime.strftime(row.User.dateofreg, '%Y-%m-%d %H:%M')
                user_info['devicetype'] = row.User.devicetype
                user_info['name']       = crypto.decodeAES(row.User.name)
                user_info['email']      = row.User.email
                user_info['phone']      = crypto.decodeAES(row.User.phone)
                user_info['gender']     = row.User.gender
                user_info['birthdate']  = crypto.decodeAES(row.User.dateofbirth)
                user_info['default_address'] = crypto.decodeAES(row.UserAddress.address) if row.UserAddress != None else ''
                user_info['default_address_size'] = row.UserAddress.size if row.UserAddress != None else ''
                user_info['default_address_kind'] = row.UserAddress.kind if row.UserAddress != None else ''

                users.append(user_info)

            ret['response'] = users
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
Exemplo n.º 16
0
class ManualChargeHandler(tornado.web.RequestHandler):
    def post(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        booking_id = self.get_argument('booking_id', '')
        price = self.get_argument('price', '')
        product_name = self.get_argument('product_name', '')

        price = int(price)

        ret = {}

        try:
            session = Session()

            try:
                row = session.query(Booking, User) \
                        .join(User, Booking.user_id == User.id) \
                        .filter(Booking.id == booking_id) \
                        .one()

            except NoResultFound, e:
                session.close()
                self.set_status(Response.RESULT_OK)
                add_err_message_to_response(ret,
                                            err_dict['err_login_no_record'])
                return

            except MultipleResultsFound, e:
                session.close()
                self.set_status(Response.RESULT_OK)
                add_err_message_to_response(ret,
                                            err_dict['err_multiple_record'])
                return

            userdao = UserDAO()

            user_id = row.User.id

            key = userdao.get_user_salt_by_id(user_id)[:16]
            crypto = aes.MyCrypto(key)

            user_name = crypto.decodeAES(row.User.name)
            appointment_type = row.Booking.appointment_type

            if row.User.devicetype == 'None':
                try:
                    record = UserPaymentRecordForIOS(booking_id, user_id,
                                                     price, dt.datetime.now())
                    session.add(record)
                    session.commit()
                    ret_code = True
                except Exception, e:
                    ret_code = False
                    value = str(e)
    def post(self):
        self.set_header("Content-Type", "application/json")

        ret = {}

        email = self.get_argument('email', '')
        pwd = self.get_argument('pwd', '')

        print 'login', email, pwd

        mongo_logger = get_mongo_logger()
        mix = get_mixpanel()

        try:
            session = Session()
            userdao = UserDAO()

            try:
                row = session.query(User) \
                            .filter(User.email == email, User.password == pwd, User.active == 1) \
                            .one()

            except NoResultFound, e:
                try:
                    if len(email) == 11 and email.startswith('010'):
                        row = session.query(User) \
                                    .filter(func.aes_decrypt(func.from_base64(User.phone), \
                                    func.substr(User.salt, 1, 16)) == email,  \
                                    User.password == pwd, \
                                    User.active == 1) \
                                    .one()
                    else:
                        session.close()
                        self.set_status(Response.RESULT_OK)
                        add_err_message_to_response(
                            ret, err_dict['err_login_no_match'])
                        mongo_logger.error('%s failed to logined' % email,
                                           extra={'err': str(e)})
                        return

                except NoResultFound, e:
                    session.close()
                    self.set_status(Response.RESULT_OK)
                    add_err_message_to_response(ret,
                                                err_dict['err_login_no_match'])
                    mongo_logger.error('%s failed to logined' % email,
                                       extra={'err': str(e)})
                    return
                except MultipleResultsFound, e:
                    session.close()
                    self.set_status(Response.RESULT_OK)
                    add_err_message_to_response(ret,
                                                err_dict['err_dup_phone2'])
                    mongo_logger.error('%s failed to logined' % email,
                                       extra={'err': str(e)})
                    return
Exemplo n.º 18
0
    def post(self):
        self.set_header("Content-Type", "application/json")

        ret = {}

        uid     = self.get_argument('user_id', '')
        master_gender    = self.get_argument('master_gender', 1)

        mongo_logger = get_mongo_logger()
        master_gender = int(master_gender)
        
        if master_gender == 2: # 남자일 경우 남자코드인 0으로 변경
            master_gender = 0

        try:
            session = Session()

            userdao = UserDAO()
            addressdao = AddressDAO()

            address = userdao.get_user_address(uid)[0]
            gu_id = addressdao.get_gu_id(address)

            master_count_by_gender = session.query(MasterPreferedArea, Master) \
                    .join(Master, MasterPreferedArea.master_id == Master.id) \
                    .filter(MasterPreferedArea.prefered_gu == gu_id) \
                    .filter(Master.gender == master_gender) \
                    .filter(Master.active == 1) \
                    .count()

            ret['response'] = {'master_count_by_gender' : master_count_by_gender}
            self.set_status(Response.RESULT_OK)

            print uid, 'request master gender, value of ', master_gender, master_count_by_gender
            mongo_logger.debug('%s request master gender count' % uid, extra={'user_id' : uid, 'master_gender' : master_gender})

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
            mongo_logger.error('%s failed to posted memo' % uid, extra = {'err' : str(e)})
Exemplo n.º 19
0
    def login(self, name, phone):
        session = Session()
        userdao = UserDAO()
        result = session.query(User) \
                    .filter(User.email == name + phone + '@11st.co.kr') \
                    .filter(User.authsource == '11st') \
                    .all()

        for row in result:
            key = userdao.get_user_salt_by_id(row.id)[:16]
            crypto = aes.MyCrypto(key)

            decrypted_name = crypto.decodeAES(row.name)
            decrypted_phone = crypto.decodeAES(row.phone)

            if name == decrypted_name and phone == decrypted_phone:  # 동명이인 고려, 일치하게 된다면 id 반환
                return row.id, True

        return '', False
    def get(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        ret = {}

        try:
            session = Session()

            result = session.query(Booking, User) \
                            .join(User, and_(Booking.user_id == User.id, and_(or_(Booking.cleaning_status == 1, Booking.cleaning_status == 2), or_(Booking.payment_status == 0, Booking.payment_status == -3)))) \
                            .filter(not_(User.email.like('*****@*****.**'))) \
                            .all()
            unpaid_datas = []
            Userdao = UserDAO()

            for record in result:
                key = Userdao.get_user_salt(record.User.email)[:16]
                if key == None or key == '':
                    continue

                crypto = aes.MyCrypto(key)

                unpaid_info = {}
                unpaid_info['booking_id'] = record.Booking.id
                unpaid_info[
                    'appointment_type'] = record.Booking.appointment_type
                unpaid_info['cleanning_date'] = dt.datetime.strftime(
                    record.Booking.start_time, '%Y-%m-%d %H:%M')
                unpaid_info['user_name'] = crypto.decodeAES(record.User.name)
                unpaid_info['user_phone'] = crypto.decodeAES(record.User.phone)
                unpaid_info['price_with_task'] = record.Booking.price_with_task
                unpaid_datas.append(unpaid_info)

            ret['response'] = unpaid_datas
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
    def post(self):
        self.set_header("Content-Type", "application/json")

        uid     = self.get_argument('uid', '')
        price   = self.get_argument('price', '')

        ret = {}

        try:
            mongo_logger = get_mongo_logger()
            mix = get_mixpanel()

            userdao = UserDAO()

            request_url = '%s:%d/homemaster_payment/request_payment' % (PAYMENT_HOST, PAYMENT_PORT)

            params = {}
            params['id']            = uid
            params['name']          = userdao.get_user_name(uid)
            params['price']         = price
            params['product_name']  = 'moving'
            

            response = requests.post(request_url, data = params)
            result = json.loads(response.text)

            if response.status_code == 200 and result['response'] == "SUCCESS":
                mix.track(uid, 'request mc payment', {'time' : dt.datetime.now(), 'tid' : result['tid'], 'authdate' : result['authdate']})
                mongo_logger.debug('%s request mc payment' % uid, extra = {'user_id' : uid, 'tid' : result['tid'], 'authdate' : result['authdate']})
                
                ret['response'] = result['response']
                self.set_status(Response.RESULT_OK)
            else:
                print 'An error occurred when paying moving clean'
                print result['err_code'], result['err_msg']
                add_err_ko_message_to_response(ret, result['err_msg'])

                mix.track(uid, 'cannot request mc payment', {'time' : dt.datetime.now(), 'code' : result['err_code']})
                mongo_logger.error('%s failed to request mc payment' % uid, extra = {'err' : result['err_msg']})
        except Exception, e:
            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
    def post(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        user_id = self.get_argument('id', '')
        tid = self.get_argument('tid', '')
        amount = self.get_argument('amount', 0)
        partial = self.get_argument('partial', 1)
        cancel_msg = self.get_argument('cancel_msg', '')

        amount = int(amount)

        if cancel_msg == '':
            cancel_msg = '취소'

        ret = {}

        try:
            mongo_logger = get_mongo_logger()
            mix = get_mixpanel()

            userdao = UserDAO()

            request_url = '%s:%d/homemaster_payment/cancel_payment' % (
                PAYMENT_HOST, PAYMENT_PORT)
            params = {}
            params['id'] = user_id
            params['tid'] = tid
            params['amount'] = amount
            params['partial'] = partial
            params['cancel_msg'] = cancel_msg

            response = requests.post(request_url, data=params)
            result = json.loads(response.text)

            if response.status_code == 200 and result['response'] != "":
                mix.track(user_id, 'cancel payment',
                          {'time': dt.datetime.now()})
                mongo_logger.debug('cancel payment',
                                   extra={'user_id': user_id})

                ret['response'] = result['response']
                self.set_status(Response.RESULT_OK)
            else:
                print 'An error occurred while register card'
                print result['err_msg']
                add_err_ko_message_to_response(ret, result['err_msg'])
                mix.track(user_id, 'cannot cancel payment',
                          {'time': dt.datetime.now()})
                mongo_logger.error('failed to cancel payment',
                                   extra={'user_id': user_id})
        except Exception, e:
            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
    def post(self):
        ret = {}

        guid = self.get_argument('id', '')
        address = self.get_argument('address', '')
        size = self.get_argument('size', 0)
        kind = self.get_argument('kind', 1)

        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        mongo_logger = get_mongo_logger()
        mix = get_mixpanel()

        try:
            session = Session()
            userdao = UserDAO()

            default_addr_index = userdao.get_user_default_address_index(guid)

            try:
                row = session.query(UserAddress) \
                            .filter(and_(UserAddress.user_id == guid, UserAddress.user_addr_index == default_addr_index)) \
                            .one()
            except NoResultFound, e:
                session.close()
                self.set_status(Response.RESULT_OK)
                add_err_message_to_response(ret, err_dict['err_no_record'])
                mongo_logger.error('%s failed to find address, no record' %
                                   email,
                                   extra={'err': str(e)})
                return

            except MultipleResultsFound, e:
                session.close()
                self.set_status(Response.RESULT_OK)
                add_err_message_to_response(ret,
                                            err_dict['err_multiple_record'])
                mongo_logger.error(
                    '%s failed to find address, multiple record' % email,
                    extra={'err': str(e)})
                return
    def is_user_block(self, ret, uid):
        try:
            mongo_logger = get_mongo_logger()
            userdao = UserDAO()

            session = Session()
            result = session.query(User) \
                            .filter(User.id == uid) \
                            .one()

            key = userdao.get_user_salt_by_id(result.id)[:16]
            crypto = aes.MyCrypto(key)
            phone = crypto.decodeAES(result.phone)

            row = session.query(BlockUser, User) \
                         .join(User, User.id == BlockUser.user_id) \
                         .filter(func.aes_decrypt(func.from_base64(User.phone), func.substring(User.salt, 1, 16)) == phone) \
                         .all()

            print row

            session.close()
            if len(row) > 0:
                self.set_status(Response.RESULT_OK)
                add_err_ko_message_to_response(
                    ret,
                    '현재 주문량이 많아 신규 예약이 불가능 합니다. 확실한 서비스 품질을 보증을 위해 바로 서비스를 제공해 드릴 수 없는 점 양해 부탁드립니다.'
                )
                mongo_logger.debug('block user', extra={'user_id': uid})
                ret['err_code'] = '4037'  # 임시 처리
                return True

            return False

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
            return True
    def post(self):
        self.set_header("Content-Type", "application/json")
        self.set_header('Access-Control-Allow-Origin', '*')

        ret = {}

        booking_id                  = self.get_argument('booking_id', '')

        uid                         = self.get_argument('uid', '')
        date                        = self.get_argument('date', dt.datetime.strftime(dt.datetime.now(), '%Y%m%d'))
        time                        = self.get_argument('time', '08:00')
        master_ids                  = self.get_argument('master_ids', [])
        apply_to_all_behind         = self.get_argument('apply_to_all_behind', 0)
        by_manager                  = self.get_argument('by_manager', 0)

        # convert parameters
        apply_to_all_behind         = int(apply_to_all_behind)
        selected_date_str           = date
        time_str                    = time
        selected_date               = dt.datetime.strptime(date, '%Y%m%d')
        master_ids                  = master_ids.split(',')
        by_manager                  = int(by_manager)

        # logging part
        mix = get_mixpanel()
        mongo_logger = get_mongo_logger()

        print 'update schedule'
        print selected_date_str, time_str, apply_to_all_behind
        print '*' * 100

        try:
            session = Session()

            booking_info = {}

            userdao     = UserDAO()
            masterdao   = MasterDAO()
            holder      = IntermediateValueHolder()

            try:
                row = session.query(Booking).filter(Booking.id == booking_id).one()
            except NoResultFound, e:
                session.close()
                self.set_status(Response.RESULT_OK)
                add_err_message_to_response(ret, err_dict['err_no_record'])
                return

            except MultipleResultsFound, e:
                session.close()
                self.set_status(Response.RESULT_OK)
                add_err_message_to_response(ret, err_dict['err_multiple_record'])
                return
Exemplo n.º 26
0
    def get(self):
        self.set_header("Content-Type", "application/json")

        ret = {}

        try:
            session = Session()
            userdao = UserDAO()

            none_ios_users = []

            for row in session.query(User, Booking) \
                            .join(Booking, User.id == Booking.user_id) \
                            .filter(Booking.cleaning_status == 0) \
                            .filter(User.devicetype == 'None') \
                            .group_by(User.id) \
                            .all():
                user_dict = {}

                user_id = row.User.id
                key = userdao.get_user_salt_by_id(user_id)[:16]
                crypto = aes.MyCrypto(key)

                user_dict['name'] = crypto.decodeAES(row.User.name)
                user_dict['email'] = row.User.email
                user_dict['phone'] = crypto.decodeAES(row.User.phone)
                user_dict['gender'] = row.User.gender

                none_ios_users.append(user_dict)

            print len(none_ios_users)
            ret['response'] = none_ios_users
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
Exemplo n.º 27
0
    def get(self):
        self.set_header("Content-Type", "application/json")
        ret = {}

        try:
            userdao = UserDAO()

            session = Session()
            result = session.query(MasterClaim, Master, User) \
                            .join(Master, MasterClaim.master_id == Master.id) \
                            .join(User, MasterClaim.user_id == User.id) \
                            .order_by(desc(MasterClaim.register_time)) \
                            .all()

            claims = []
            for row in result:
                key = userdao.get_user_salt_by_id(row.User.id)[:16]
                crypto = aes.MyCrypto(key)

                claim = {}
                claim['user_name'] = crypto.decodeAES(row.User.name)
                claim['user_phone'] = crypto.decodeAES(row.User.phone)
                claim['master_name'] = row.Master.name
                claim['text'] = row.MasterClaim.claim_text
                claim['datetime'] = convert_datetime_format2(
                    row.MasterClaim.register_time)

                claims.append(claim)

            ret['response'] = claims
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
Exemplo n.º 28
0
    def notify(self):
        try:
            userdao = UserDAO()

            current_date = dt.datetime.now().date()

            print current_date

            session = Session()
            result = session.query(Booking, User, UserPushKey) \
                        .join(User, Booking.user_id == User.id) \
                        .join(UserPushKey, User.id == UserPushKey.user_id) \
                        .filter(func.date(Booking.start_time) == current_date) \
                        .filter(Booking.cleaning_status == BC.BOOKING_COMPLETED) \
                        .all()

            for row in result:
                key = userdao.get_user_salt_by_id(row.User.id)[:16]
                crypto = aes.MyCrypto(key)

                booking_id = row.Booking.id
                user_name  = crypto.decodeAES(row.User.name)
                pushkey    = row.UserPushKey.pushkey
                devicetype = row.User.devicetype

                if row.Booking.havereview == 0: # review 하지 않은 사용자에게만 보냄
                    print 'rating push to ', user_name, booking_id

                    if devicetype != 'android':
                        pushkey = crypto.decodeAES(row.User.phone)

                    send_rating_notification(devicetype, [pushkey], booking_id, user_name)

            print 'notified to users for rating successfully...', dt.datetime.now()

        except Exception, e:
            print_err_detail(e)
    def get(self):
        self.set_header("Content-Type", "application/json")

        ret = {}

        try:
            session = Session()
            userdao = UserDAO()

            users = []

            for row in session.query(User, UserAddress, UserDefaultAddress, Booking) \
                            .outerjoin(UserAddress, User.id == UserAddress.user_id) \
                            .outerjoin(UserDefaultAddress, User.id == UserDefaultAddress.user_id) \
                            .outerjoin(Booking, and_(User.id == Booking.user_id)) \
                            .all():

                if row.UserAddress != None and row.Booking == None:
                    user_id = row.User.id
                    key = userdao.get_user_salt_by_id(user_id)[:16]
                    crypto = aes.MyCrypto(key)

                    user_info = {}
                    user_info['name'] = crypto.decodeAES(row.User.name)
                    user_info['phone'] = crypto.decodeAES(row.User.phone)

                    users.append(user_info)

            ret['response'] = users
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])
Exemplo n.º 30
0
    def get(self):
        self.set_header("Content-Type", "application/json")

        ret = {}

        try:
            session = Session()
            userdao = UserDAO()

            memos = []

            result = session.query(UserMemo, User) \
                            .join(User, UserMemo.user_id == User.id) \
                            .order_by(desc(UserMemo.requested_datetime)) \
                            .all()

            for row in result:
                key = userdao.get_user_salt_by_id(row.User.id)[:16]
                crypto = aes.MyCrypto(key)

                memo = {}
                memo['time'] = dt.datetime.strftime(
                    row.UserMemo.requested_datetime, '%Y-%m-%d %H:%M')
                memo['memo'] = row.UserMemo.memo
                memo['user_name'] = crypto.decodeAES(row.User.name)
                memos.append(memo)

            ret['response'] = memos
            self.set_status(Response.RESULT_OK)

        except Exception, e:
            session.rollback()

            print_err_detail(e)
            self.set_status(Response.RESULT_SERVERERROR)
            add_err_message_to_response(ret, err_dict['err_mysql'])