コード例 #1
0
    def post(self):

        email = self.get_argument("email", "")
        password = self.get_argument("password", "")
        ajax = self.get_argument("ajax", "false")
        user_id = self.get_argument("user_id", "")

        # print "user_id {}".format(user_id)

        if email == "":
            self.write("debe ingresar el email")
        elif password == "":
            self.write("debe ingresar la contraseña")
        else:
            user = User()
            user.email = email
            user.password = password

            response_obj = user.Login(user.email, user.password)

            if "success" in response_obj:

                self.set_secure_cookie("user_giani",
                                       response_obj["success"],
                                       expires_days=None)

                current_user_id = json_util.loads(
                    response_obj["success"])["id"]

                if user_id != current_user_id:

                    cart = Cart()

                    cart.MoveTempToLoggedUser(user_id, current_user_id)

                # if "error" in response:
                #     rtn_obj = {"status":"error","message":"Usuario y contraseña no coinciden, error:{}".format(response["error"])}
                #     self.write( json_util.dumps(rtn_obj) )
                #     return

                rtn_obj = {
                    "status": "ok",
                    "next": self.next,
                    "user_id": current_user_id
                }
                self.write(json_util.dumps(rtn_obj))

                if ajax == "false":
                    self.redirect(self.next)

            else:
                rtn_obj = {
                    "status": "error",
                    "message": "Error:{}".format(response_obj["error"])
                }
                self.write(json_util.dumps(rtn_obj))
コード例 #2
0
    def post(self):

        name = self.get_argument("name", "")
        email = self.get_argument("email", "")
        password = self.get_argument("password", "")
        re_password = self.get_argument("re-password", "")
        tos = self.get_argument("tos", "")
        ajax = self.get_argument("ajax", "false")
        user_id = int(self.get_argument("user_id", 0))

        # print tos

        if name == "":
            self.write(json_util.dumps({"error": "debe ingresar su nombre"}))
            return
        elif email == "":
            self.write(json_util.dumps({"error": "debe ingresar el email"}))
            return
        elif password == "":
            self.write(
                json_util.dumps({"error": "debe ingresar la contraseña"}))
            return
        elif password != re_password:
            self.write(
                json_util.dumps({"error": "las contraseñas no coinciden"}))
            return
        elif tos != "on":
            self.write(
                json_util.dumps(
                    {"error": "debe aceptar las condiciones de uso"}))
            return
        else:

            response = User().Exist(email)

            if "success" in response:
                if response["success"]:
                    self.write(
                        json_util.dumps({
                            "error":
                            "ya existe un usuario registrado con este email"
                        }))
                    return
            else:
                self.write(
                    json_util.dumps({
                        "error":
                        "se ha producido un error {}".format(response['error'])
                    }))
                return

            # perform login

            user = User()
            user.name = name
            user.email = email
            user.password = password
            user.user_type = UserType.CLIENTE
            user.status = User.ACEPTADO

            if user_id != 0:
                existe = User().Exist('', user_id)
                if "success" in existe:
                    if existe["success"]:
                        user.id = user_id

            user.Save()

            RegistrationEmail(user.name, user.email)

            response_obj = user.Login(user.email, user.password)

            if "success" in response_obj:

                self.set_secure_cookie("user_giani",
                                       response_obj["success"],
                                       expires_days=None)

                current_user_id = json_util.loads(
                    response_obj["success"])["id"]

                if user_id != current_user_id:

                    cart = Cart()

                    response = cart.MoveTempToLoggedUser(
                        user_id, current_user_id)

                self.write(json_util.dumps({"success": self.next}))
                return
            else:
                self.write(json_util.dumps({"error": str(response_obj)}))
                return

            # redirect is the request isn't aajx
            if ajax == "false":
                self.set_secure_cookie("user_giani",
                                       response_obj["success"],
                                       expires_days=None)
                self.write(json_util.dumps({"success": self.next}))
コード例 #3
0
    def _save_user_profile(self, user):

        if not user:
            raise tornado.web.HTTPError(500, "Facebook authentication failed.")

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

        usr = User()

        usr.name = user["name"]
        usr.email = user["email"]
        usr.user_type = UserType.VISITA

        if user_id != "":
            usr.id = user_id

        response = usr.Exist(user["email"])

        if "success" in response:
            if not response["success"]:
                res = usr.Save()
                RegistrationEmail(usr.name, usr.email)
                if "error" in res:
                    print res["error"]

        else:
            self.render("auth/fail.html", message=response["error"])

        response_obj = usr.InitByEmail(user["email"])

        # print response_obj

        if "success" in response_obj:

            current_user_id = json_util.loads(response_obj["success"])["id"]

            # print "user_id: {} current_user_id: {}".format(str(user_id),str(current_user_id))

            if user_id != "":

                if str(user_id) != str(current_user_id):

                    cart = Cart()

                    response = cart.MoveTempToLoggedUser(
                        user_id, current_user_id)

                    # if "error" in response:
                    #     print "Error moving cart detail: {}".format(response["error"])

            self.set_secure_cookie("user_giani",
                                   response_obj["success"],
                                   expires_days=0.02)

            _u = User()

            _u.updateLastView(
                current_user_id,
                datetime.now(pytz.timezone('Chile/Continental')).isoformat())

            self.redirect(self.next)

        else:

            self.render("auth/fail.html", message=response_obj["error"])

        # else:

        #     self.write(response_obj["error"])

        # conn = psycopg2.connect(conn_string)

        # cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)

        # # self.write(user)

        # # return

        # cursor.execute("select * from \"user\" where email = %(email)s",{"email":user["email"]})

        # data = cursor.fetchone()

        # _user = {}

        # if data:
        #     _user["id"] = data["id"]
        #     _user["name"] = data["name"]
        #     _user["email"] = data["email"]
        #     _user["type"] = data["type"]
        #     _user["profile"] = data["profile"]

        #     print "ya existe"
        #     self.write("el usuario con el email ya existe")
        # else:

        #     parameters = {"email":user["email"],"name":user["name"],"type":"facebook"}

        #     try:
        #         cursor.execute("insert into \"user\" (email, name, type) values (%(email)s,%(name)s,%(type)s)",parameters)
        #         conn.commit()

        #         try:
        #             cursor.execute("select * from \"user\" where email = %(email)s",{"email":user["email"]})
        #             data = cursor.fetchone()
        #             if data:
        #                 _user["id"] = data["id"]
        #                 _user["name"] = data["name"]
        #                 _user["email"] = data["email"]
        #                 _user["type"] = data["type"]
        #                 self.write("usuario creado correctamente")
        #         except Exception, e:
        #             self.write(str(e))
        #     except Exception,e:
        #         self.write(str(e))

        # self.set_secure_cookie("user_giani", json_util.dumps(_user, sort_keys=True, indent=4, default=json_util.default))
        # self.redirect("/")

        pass