def get(self): user_id = int(self.get_argument("user_id", 0)) user = User() if self.current_user: self.write(json_util.dumps({"success": self.current_user["id"]})) elif user_id != 0: exists_response = user.Exist('', user_id) if "success" in exists_response: existe = exists_response["success"] if not existe: user.user_type = UserType.VISITA user.status = User.ACEPTADO response_obj = user.Save() self.write(json_util.dumps(response_obj)) else: self.write(json_util.dumps({"success": user_id})) else: self.write(json_util.dumps(exists_response)) else: user.user_type = UserType.VISITA response_obj = user.Save() self.write(json_util.dumps(response_obj))
def get(self): user_id = self.get_argument("user_id", "") if user_id != "": user = User() response_obj = user.Exist('', user_id) if "success" in response_obj: if response_obj["success"]: self.write("true") else: self.write("false") else: self.write("false") else: self.write("false")
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