Example #1
0
    def post(self, email):

        # Http 쏘기 위한 공옹 루틴
        self.response.headers.add_header("Access-Control-Allow-Origin", "*")
        self.response.content_type = "application/json"

        user = db.UserEntity.get_by_id(email)
        if user == None:
            res_data = {"result": False, "reason": "email not exist"}
            self.response.write(json.encode(res_data))
            return

        # 패스워드 틀림
        req_data = json.decode(cgi.escape(self.request.body))
        if user.password != req_data["password"]:
            res_data = {"result": False, "reason": "password not match"}
            self.response.write(json.encode(res_data))
            return

        # 결과 리턴
        token = secret.get_jwt(user.auth_type, user.email, user.name)
        res_data = {
            "result": True,
            "token": token,
            "isWorking": user.is_working,
            "totalWorkingSeconds": (datetime.now() - user.work_start_date_time).total_seconds(),
        }
        if user.intro_text != None:
            res_data["introText"] = user.intro_text
        if user.avatar_photo_blob_key != None:
            userPhoto = db.BlobEntity.get_by_id(str(user.avatar_photo_blob_key))
            if userPhoto != None:
                res_data["avatarPhotoUrl"] = userPhoto.blob_url
        self.response.write(json.encode(res_data))
Example #2
0
    def post(self, email):

        # Http 쏘기 위한 공옹 루틴
        self.response.headers.add_header("Access-Control-Allow-Origin", "*")
        self.response.content_type = "application/json"

        user = db.UserEntity.get_by_id(email)
        if user != None:
            res_data = {"result": False, "reason": "email occupied"}
            self.response.write(json.encode(res_data))
            return

        # 유저 생성
        req_data = json.decode(cgi.escape(self.request.body))
        user = db.UserEntity(id=email)
        user.email = email
        user.name = req_data["name"]
        user.auth_type = "ototalk_auth"
        user.password = req_data["password"]
        if req_data.get("avatarPhotoBlobId") != None:
            userPhoto = db.BlobEntity.get_by_id(req_data["avatarPhotoBlobId"])
            if userPhoto != None:
                user.avatar_photo_blob_key = userPhoto.blob_key
                userPhoto.is_assigned = True
                userPhoto.put()
        user.put()

        # 응답
        token = secret.get_jwt(user.auth_type, user.email, user.name)
        res_data = {
            "result": True,
            "token": token,
            "isWorking": user.is_working,
            "totalWorkingSeconds": (datetime.now() - user.work_start_date_time).total_seconds(),
        }
        if req_data.get("avatarPhotoBlobId") != None and userPhoto != None:
            res_data["avatarPhotoUrl"] = userPhoto.blob_url
        self.response.write(json.encode(res_data))