YouTube2Text

How to Create website Controller in Odoo 18 | Handle Public and User Authentication — Transcript

by Odoo Tech · 2,895 words · 389 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hello, welcome to my YouTube channel.
  2. 0:03So, in this video, we will show you how
  3. 0:05to create the website controller. Okay.
  4. 0:08So, like whenever you hit any URL on
  5. 0:11the website. So, this is your URL. Okay
  6. 0:15, you know whenever you write any URL
  7. 0:18here, what page will reload on the
  8. 0:20website? Like, in this URL, you can see
  9. 0:23this page. Okay? So basically, similar
  10. 0:27to this, write the URL here, and see
  11. 0:31what message will show on your screen,
  12. 0:34how to create the API, and how you will
  13. 0:38get the user data from your work data
  14. 0:41sent on the portal site. Okay, so you
  15. 0:45have to create the API with the POST
  16. 0:47method and many other things; we will
  17. 0:49cover every small thing in this video.
  18. 0:52Okay, so let's start, without wasting
  19. 0:56much time. Okay. First, I have already
  20. 0:58created the module, and this is Odoo 18
  21. 1:01version, and this is Enterprise. You
  22. 1:04can also use the Community version. The
  23. 1:06same module will work on the Community
  24. 1:07version. Okay. So first, let me show
  25. 1:11you the module; I am going to my file
  26. 1:14technical site. Okay. So, this is my
  27. 1:19custom addons. Here, I have created one
  28. 1:22module; the name of this module is
  29. 1:24website_controller, okay. So, in this
  30. 1:27website_controller module, I created a
  31. 1:30folder named controllers; in this
  32. 1:33folder, we have to write the code
  33. 1:36related to the website, okay. Which
  34. 1:39code will work on the website portal?
  35. 1:42Basically, whenever any URL is hit,
  36. 1:45that code and that file will run, okay.
  37. 1:48Based on this, inside this, we create
  38. 1:50an init file; this is the internal init
  39. 1:52file. After that, creating the main
  40. 1:54file; the main file is the Python file,
  41. 1:57okay. So, that file is imported in the
  42. 2:00init file, okay. After that, I have
  43. 2:03created an external file; we have to
  44. 2:06link the controller module in this file
  45. 2:08. After that, the manifest; in this
  46. 2:11module, the manifest will tell you
  47. 2:13about the module. You can write a
  48. 2:15message according to your requirement
  49. 2:17and what the version of the module will
  50. 2:19be, okay. So, I am adding the
  51. 2:21dependencies for two modules: base and
  52. 2:24website. Okay. Now, going to the main
  53. 2:28file. So, let's explain the code to you
  54. 2:30. So, first, I am importing the http
  55. 2:33code and second is the http request.
  56. 2:36Okay? So, this is the first module,
  57. 2:40okay? My first controller writes a
  58. 2:43website controller. If you go to the
  59. 2:45http folder file. So, there you can see
  60. 2:48one class that is Controller. Okay, in
  61. 2:51the controller you have to write the
  62. 2:53URL. Okay, we are now going to extend
  63. 2:58the functions. Now you can see the
  64. 3:01function Hello World. First is the
  65. 3:04public user. In the route, in the
  66. 3:06route's first parameter we have to pass
  67. 3:09the URL. Okay, whenever you hit this
  68. 3:12URL, this message will show on the
  69. 3:14website page. Okay. After that, write
  70. 3:18HTTP here, so the type is HTTP. So,
  71. 3:23whenever you click on the website, that
  72. 3:26URL will be hit. Okay. Auth, auth means
  73. 3:29authentication. There are two types:
  74. 3:31public and user, so here we have public
  75. 3:33and user. If it is public, if you write
  76. 3:36here auth is public, then anyone can
  77. 3:39access this URL and get the data on the
  78. 3:41page. Okay. And if you write user here,
  79. 3:45then you have to be a part of the Odoo
  80. 3:51user. Like if in Odoo you have created
  81. 3:54three to four users, then only those
  82. 3:57users can access the URL. Okay. And
  83. 4:01website equals true, so it means that
  84. 4:04this URL will be hit on the portal site
  85. 4:06. Okay. URL website Google. Now let me
  86. 4:11show you one by one. So, I am creating
  87. 4:15one folder named Hello World and
  88. 4:16passing one argument as a keyword, you
  89. 4:18can pass the value and it. Okay. Now
  90. 4:22when I am going to, first let's install
  91. 4:26and upgrade the module. Go to Apps and
  92. 4:32install website. So, basically I have
  93. 4:37already installed this module. Okay. I
  94. 4:40am going to upgrade my name is Singh.
  95. 4:49So, basically it is that whenever we
  96. 4:51create a module, we have to install it
  97. 4:53first, and what we do is that whatever
  98. 4:55module or controller we have created,
  99. 4:57we write all the website-related code
  100. 4:59inside the controller itself. Inside
  101. 5:02the controller, we extend our own class
  102. 5:05, which is the controller class. The
  103. 5:07function is written inside that. What
  104. 5:08do we pass in the first route? We pass
  105. 5:10a URL on which our function will work,
  106. 5:13and where this URL will be hit and what
  107. 5:16type it will be, we decide that here,
  108. 5:18whether it will be HTTP, meaning a
  109. 5:20website URL. And the second is the
  110. 5:23authentication, meaning anyone can
  111. 5:25access it. If auth user is written here
  112. 5:28, then it must be an Odoo user; whoever
  113. 5:31is an Odoo user can access it,
  114. 5:34otherwise no one can access that URL.
  115. 5:37Okay, website equals to true, it means
  116. 5:40that this URL will hit the Google page.
  117. 5:43Okay, let's start with Chrome, and let
  118. 5:47me show you how it works. So I am
  119. 5:53copying this and going to the form. Now
  120. 5:58remove this part, paste it here, and
  121. 6:02click Enter. So here we will print,
  122. 6:05here we will print Hello World. This is
  123. 6:08my first controller in Odoo 18, okay?
  124. 6:12On Enter, you can see this message here
  125. 6:16, okay? You can design this page with
  126. 6:20HTML and CSS. So, in the next video I
  127. 6:23make, we will design our entire website
  128. 6:26page, how to send data, how to create a
  129. 6:28form, how to create it, and everything
  130. 6:31will hit here, okay? We will also see
  131. 6:34later which page to hit on what. For
  132. 6:38now, we are just understanding the
  133. 6:40basic things of how to modify the
  134. 6:41website controller and how it is used.
  135. 6:44Okay? So this was our first one. Now,
  136. 6:47let me do one thing and open this in a
  137. 6:50private window where I am not logged in
  138. 6:52. Right? I am not logged in here, and I
  139. 6:55am accessing it. So, I am able to
  140. 6:57access it. And if I talk about the
  141. 7:00second URL. Here I have written user,
  142. 7:04so I should be logged in already to
  143. 7:07access it. Otherwise, what will it give
  144. 7:10me? It will give an error. Let me show
  145. 7:12you. I simply pasted it and hit enter.
  146. 7:20So It means it is saying that either
  147. 7:24you log in, only then you can redirect
  148. 7:26it. Sometimes this page will give
  149. 7:29errors. Okay, otherwise you have to log
  150. 7:32in to the system, then you can access
  151. 7:35it. And if I use this same URL here,
  152. 7:38then it will work. Because I am already
  153. 7:41logged in. I am already logged in in
  154. 7:43this window. In this window, I am
  155. 7:46already logged in with the admin user.
  156. 7:49Okay, now click on the URL, it works.
  157. 7:53Hello Admin, you are logged in. Okay,
  158. 7:57but if I do it in an incognito window,
  159. 8:02it will say that you have to log in to
  160. 8:04the system first, then you can access
  161. 8:06the URL. Okay, Now, let's move to the
  162. 8:15second and third one, JSON API response
  163. 8:19. So, for JSON API response, at both
  164. 8:22public and user levels, it's the same
  165. 8:23thing with these functions. Whenever
  166. 8:26you need to create an API, like an API
  167. 8:29for contact creation, importing
  168. 8:31products, exporting products, or any
  169. 8:33export according to your requirement,
  170. 8:36you can create the API in the system.
  171. 8:39Okay, so as I explained in the first
  172. 8:42one, pass the URL here, and this is the
  173. 8:46same thing. So now, whenever you click
  174. 8:49on it, whenever you pass JSON type data
  175. 8:51, you have to write "type equals JSON"
  176. 8:53here. So, the data you are posting from
  177. 8:57here, that data will come into your
  178. 8:59function, which will trigger your
  179. 9:01function in your system; it must be of
  180. 9:04JSON type only then can we retrieve
  181. 9:06that data. Okay, authentication is
  182. 9:08public; anyone can send the data. Okay,
  183. 9:11and here we have to pass the method,
  184. 9:13whether you are sending data or
  185. 9:15retrieving it; if you are sending data
  186. 9:17then you will use "POST," and if you
  187. 9:19are retrieving, then you will use the "
  188. 9:21GET" method here. Okay, so then I
  189. 9:23created a variable here for HTTP, which
  190. 9:26I imported, then "http request dot json
  191. 9:29," meaning the data I am sending there
  192. 9:32in the JSON file, I am bringing that
  193. 9:34data here, retrieving it, and then
  194. 9:37printing it here, so whatever data I
  195. 9:40send will be printed. Right, currently
  196. 9:43I am just printing it, but you can
  197. 9:45create records in the system, like once
  198. 9:48you have the data, you can create a
  199. 9:50contact, create a sales order, create a
  200. 9:52purchase, or create anything else you
  201. 9:54want to create in the system according
  202. 9:57to your needs. Basically, this is about
  203. 10:00getting the data and knowing how to
  204. 10:02retrieve it. Okay? Then the similar
  205. 10:07thing for this user is that if you are
  206. 10:08an Odoo user, only then can you send
  207. 10:10data and only then can you create
  208. 10:11something. Otherwise, you cannot. Okay?
  209. 10:15So, like if I go here So I am going
  210. 10:27here, let's go somewhere. Go to the
  211. 10:39Open source I want to show you
  212. 10:50something. See, so you can see here
  213. 11:15that name, phone number, email, and
  214. 11:18subject are there; this is a page
  215. 11:21created for you to send any message if
  216. 11:24you want. So here, you can see that I
  217. 11:27am not logged into this. So I can send
  218. 11:30data from here. Then whoever handles
  219. 11:33this website, this page, and this
  220. 11:35database will receive the data. Then
  221. 11:38they will contact me to ask what the
  222. 11:40query is. They will solve my issue.
  223. 11:41They will revert back to me. Okay? The
  224. 11:43email that I am sending. The number
  225. 11:45that I am writing and sending in it. So
  226. 11:47this is public. If I had logged in,
  227. 11:49only then I could have raised a ticket.
  228. 11:52Only then could I have contacted them.
  229. 11:56Okay? Only then could I have contacted
  230. 11:58them. If you are part of this website
  231. 12:01you can contact them. If you are not
  232. 12:04part of this website, then it means
  233. 12:07they are using a public user. Okay?
  234. 12:10Right now I am a public user. If I am
  235. 12:13logged into the system, if I am logged
  236. 12:14in. Then, I am an internal user part of
  237. 12:17this website. Okay, so let's start by
  238. 12:21going here. So, on this website, if I
  239. 12:26click on this, a bad request comes up.
  240. 12:31Like, let me show you, because you can
  241. 12:35send data via Postman. Okay, method not
  242. 12:40allowed! It says, method not allowed,
  243. 12:43because I am not passing website equals
  244. 12:45true here and also not passing the
  245. 12:48method equals post here. That's why the
  246. 12:51error is showing on the website form.
  247. 12:54So, you have to install Postman. I have
  248. 12:57already installed it, so you have to
  249. 13:01install this module, this app, on your
  250. 13:05system. Once you install this
  251. 13:07application on your system, you can
  252. 13:10post the data. Okay, so let me show you
  253. 13:13. So click on New. As soon as you click
  254. 13:24on New, you have to click on this. This
  255. 13:27will be created for you. Then you have
  256. 13:30to go here. Then go to the Click on New
  257. 13:35. Once you click on New. Click on HTTP,
  258. 13:38after that click on HTTP. Once you
  259. 13:40click on HTTP request, the same page
  260. 13:43will appear here but empty, okay. You
  261. 13:46have to paste the URL here that you
  262. 13:48first have to copy from the website.
  263. 13:51Going to the website, you have to copy
  264. 13:55this part with Ctrl + C, or you can
  265. 13:59copy and paste it here, okay, and paste
  266. 14:03here, okay. Once I click here, here you
  267. 14:07can see your cookies and Postman. Some
  268. 14:11keys required in Postman will
  269. 14:13automatically come in the header. If
  270. 14:16you want to add any extra keys, you can
  271. 14:18add them, okay. In the body section, we
  272. 14:21have to send the data in a JSON type
  273. 14:23like a dictionary, okay. So here I am
  274. 14:25creating one dictionary, and in this
  275. 14:27dictionary, I will pass my name, city,
  276. 14:29and mobile number. I am not from Jaipur
  277. 14:31, okay, and this is not my contact
  278. 14:34number, please do not send messages,
  279. 14:37okay. So this is dummy data, and as I
  280. 14:40click on the send button, the data will
  281. 14:44show here, okay. Let's click on it, so
  282. 14:48let me show you the code here. Here you
  283. 14:54can see the first message is status
  284. 14:56equals success, second is hello from
  285. 14:58JSON API, okay, and the third is the
  286. 15:00received data, what data will come in
  287. 15:03this request JSON form, okay. So in the
  288. 15:06body section, set it here to raw and
  289. 15:08then select JSON. So once I click on
  290. 15:11that part, the data will be printed
  291. 15:13here. Okay? If I change it here like M
  292. 15:19M Del Akash. Okay. So once I update the
  293. 15:31data and click on send, then that data
  294. 15:34will update here. Okay, click on this.
  295. 15:38So here you can see my name is Akash
  296. 15:40Singh and the city. So Okay, developers
  297. 15:45can get the data and use it accordingly
  298. 15:47. Okay, so this is the public user.
  299. 15:51Right now, I am using the public user.
  300. 15:54Okay. After that, this user-this is the
  301. 15:58user type. First, we have to log in to
  302. 16:02the system. Okay, first we have to log
  303. 16:06in to Postman, after that I can access
  304. 16:09it. Okay, I am already logged in. Let's
  305. 16:13see if it gives an error or not, maybe
  306. 16:19it will. Okay, I am going to send data.
  307. 16:26Okay, I am already logged in. Okay, so
  308. 16:31let's copy and create a new one. Sorry,
  309. 16:36something Body raw section, so copy the
  310. 16:45data from here. The message will come
  311. 16:49here, and change the method to POST.
  312. 16:53Now click on send. Yeah, I am already
  313. 16:56logged in to the system. That's because
  314. 16:59the cookies are saved in the header
  315. 17:00sections. Cookies are shared, the
  316. 17:03session ID is saved here. Okay, so that
  317. 17:07is why the session is logged in. Let me
  318. 17:12click on it and right now sending the
  319. 17:19data. Yeah, right. So I want to show
  320. 17:23this part; whenever you click send data
  321. 17:27from the user side, this message will
  322. 17:30come to you: Odoo session expired. Okay
  323. 17:33, okay. First, you have to log in to
  324. 17:35the system, otherwise, you cannot post
  325. 17:38the data. So let's copy and paste it
  326. 17:46here. I am going to comment out the
  327. 17:50above part. Okay, so here is the
  328. 17:53database name, what is your database
  329. 17:55name, second is the login ID, here you
  330. 17:58have to enter the login ID and third is
  331. 18:00the password. You have to pass the data
  332. 18:04in the same way, and after that, you
  333. 18:06have to change the URL here. Okay, so
  334. 18:09the URL will be-The URL will be
  335. 18:16authentication. This URL, you need this
  336. 18:21URL, hit this URL. Now change the URL.
  337. 18:25Now I am changing the URL. So we have
  338. 18:28to send data to this URL, which means I
  339. 18:31will log in here. As soon as I log in,
  340. 18:34it will print some data here showing
  341. 18:36what I am right now, I am a public user
  342. 18:39, I mean an internal user, sorry, I am
  343. 18:41an internal user. You can check here
  344. 18:44right now that 'is internal' equals
  345. 18:46true and 'public' equals false. Meaning
  346. 18:48I am not a public user right now, I am
  347. 18:50an internal user, I can access anything
  348. 18:52inside this. Okay, I can post data.
  349. 18:55Okay, I did this much, commented it,
  350. 18:58and now I will run the query above,
  351. 19:02okay? I will copy the URL again and
  352. 19:07paste it here. Now it will work. Okay,
  353. 19:13you can see if I want to add something
  354. 19:16like an address. Okay. Okay, let's
  355. 19:30click on. So it will print here. So
  356. 19:34that is why I am showing you four types
  357. 19:37of methods and four types of URLs here.
  358. 19:41First is the website and public user,
  359. 19:44second is the user internal user
  360. 19:47website, and third is how to send the
  361. 19:51JSON API, okay, public and fourth is
  362. 19:54internal. So I showed you four types of
  363. 19:58URLs. How we can send data from our
  364. 20:02website in the controller, how to use
  365. 20:04the POST method, what the
  366. 20:06authentication user types are, and I
  367. 20:09also showed the URL types; if you want
  368. 20:11to send JSON type, it will be JSON,
  369. 20:14otherwise, it will be HTTP there. Okay,
  370. 20:18there are many more things, other
  371. 20:20parameters and other arguments. I will
  372. 20:22show you in the next videos. So that is
  373. 20:25all for this video. We will discuss the
  374. 20:28rest in the next video. I hope this
  375. 20:31file—I will paste it in my
  376. 20:33description, you can get the data from
  377. 20:36there, okay. If you want to take this
  378. 20:40module, basically it would be better if
  379. 20:42you write the code yourself. If you
  380. 20:44write the code on your own, it will be
  381. 20:47good for you. Because you know every
  382. 20:50point: why we write the name, why we
  383. 20:53write the function name, what the URL
  384. 20:56and type is, and what mistakes you are
  385. 20:59making, so check it. I have already
  386. 21:02pasted it in the description of my
  387. 21:03video. So thank you. If you have any
  388. 21:06queries, any questions, you can comment
  389. 21:08them down below. Okay, so thank you.

About this transcript

This page contains the full transcript of How to Create website Controller in Odoo 18 | Handle Public and User Authentication by Odoo Tech , generated from the public captions YouTube serves with the video. The transcript has 2,895 words across 389 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.