<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abdullah Alrasheed on Medium]]></title>
        <description><![CDATA[Stories by Abdullah Alrasheed on Medium]]></description>
        <link>https://medium.com/@twistedhardware?source=rss-3a7cc5881c2c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*E-nzPbJaNiXJ-h4K.</url>
            <title>Stories by Abdullah Alrasheed on Medium</title>
            <link>https://medium.com/@twistedhardware?source=rss-3a7cc5881c2c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 08:47:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@twistedhardware/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Secure File Sharing App in Golang (The Concept)]]></title>
            <link>https://medium.com/uadmin/secure-file-sharing-app-in-golang-the-concept-a90dfc68ddc3?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a90dfc68ddc3</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Sat, 21 Mar 2020 14:12:44 GMT</pubDate>
            <atom:updated>2020-03-21T14:12:44.025Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HT1tZ3b87cVMhS0l" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let’s build a simple file drop application to send files to other people. The application should be very simple:</p><ul><li>Drop a file in a webpage</li><li>Get a shareable link</li><li>Someone else uses the link to download the file</li><li>Delete the file after it is downloaded from the server</li></ul><h3>So where is the “secure” part?</h3><p>We will take care of this part using a couple of things:</p><ul><li>We will surely use SSL</li><li>Encrypt the files while they are on the server using a random key</li><li>Don’t keep the key of the server</li></ul><h4>The process of sending the file</h4><ol><li>Once a file is uploaded, we a generate a random base64 string which is 24 letters. This is our encryption key.</li><li>Use AES to encrypt the file using the encryption key ENCRYPTION_KEY.</li><li>Hash the the encryption key using SHA-512. This is the storage key STORAGE_KEY.</li><li>Save two files under a folder named using the storage key: /files/{STORAGE_KEY}/content and files/{STORAGE_KEY}/name</li><li>content contains the content of the file encrypted using the encryption key. name contains the file name encrypted using the same encryption key.</li><li>Give a sharing link to the file sender that looks like: <a href="https://exmaple.com/%7BSTORAGE_KEY%7D">https://exmaple.com/{ENCRYPTION_KEY}</a></li></ol><p>This will ensure that the server will contain the file and the file name in an encrypted form. At the same time the server will not know what is the encryption key.</p><h4>The process of receiving the file</h4><ol><li>Once the server receives a request to download a file, the server will receive the the encryption key and hash it to find the storage key.</li><li>Using the storage key, the server can find the file content and file name and decrypt both of them.</li><li>The server sends the file to the user decrypted and named using the original file name.</li><li>Overwrite the file many times to ensure the original content is net recoverable.</li><li>Delete the file.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a90dfc68ddc3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/uadmin/secure-file-sharing-app-in-golang-the-concept-a90dfc68ddc3">Secure File Sharing App in Golang (The Concept)</a> was originally published in <a href="https://medium.com/uadmin">uAdmin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uAadmin the Golang Web Framework #10 Schema Basics]]></title>
            <link>https://medium.com/@twistedhardware/uaadmin-the-golang-web-framework-10-schema-basics-fd2dd278b5d?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd2dd278b5d</guid>
            <category><![CDATA[web-framework]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Thu, 06 Dec 2018 12:42:38 GMT</pubDate>
            <atom:updated>2018-12-06T12:42:38.806Z</atom:updated>
            <content:encoded><![CDATA[<h3>IMPORTANT (BEFORE YOU START)</h3><blockquote>If you installed uAdmin before December 4th <em>version 0.1.0-beta.5</em>, please update your uAdmin installation (<strong>If you are not sure, just update it anyway</strong>):</blockquote><pre>go get -u github.com/uadmin/uadmin/...</pre><blockquote>After you do that go to your project’s folder and run:</blockquote><pre>uadmin prepare</pre><blockquote>This will update uAdmin templates and static files.</blockquote><h3>Schema Basics</h3><p>Each model you register in uAdmin using uadmin.Register() generates a schema in the type of a uadmin.ModelSchema. These model schema instances contain all the information the system need to know about your model and it’s fields.</p><p>These uadmin.ModelSchema instances are stored in uadmin.Schema which is a map of string that returns a uadmin.ModelSchema where the key of the map if the name of the model in small letters.</p><p>Let’s take a look at your model Todo in models/todo.go:</p><pre>...<br>type Todo struct {<br>  uadmin.Model<br>  Name        string     `uadmin:&quot;required;pattern:.{5,100};pattern_msg:Name length should be 5-100 letters&quot;`<br>  Description string     `uadmin:&quot;html&quot;`<br>  TargetDate  *time.Time `uadmin:&quot;required&quot;`<br>  Progress    int        `uadmin:&quot;progress_bar:30:red,70:yellow,100:green;min:0;max:100&quot;`<br>  Task        Task<br>  TaskID      uint<br>}<br>...</pre><p>When you register this model using uadmin.Register, uAdmin generates a uadmin.ModelSchema of your model. Let’s examine this schema and see what can we do with it.</p><p>In our app so far we have two models:</p><ul><li>Todo</li><li>Task</li></ul><p>After registering both models using uadmin.Register and registering the inlines, we can check the schema of both models. To check first the Todo model’s schema, you can access it using uadmin.Schema[&quot;todo&quot;]. Notice that we used todo NOT Todo because all models are registered using their name is small letters.</p><p>The schema of our Todo model stored in uadmin.Schema[&quot;todo&quot;] is a uadmin.ModelSchema object which has the following fields:</p><ul><li>Name: The name of the Model. In this case equals “Todo”</li><li>DisplayName: A human readable version of the name of the Model. In this “Todo. But if the model name was “TodoItem” the DisplayName would be “Todo Item”</li><li>ModelName: A the same as the Name but in small letters. In this case equals “todo”</li><li>ModelID: (<strong>Data</strong>) A place holder to store the primary key of a single row for form processing.</li><li>Inlines: A list of associated inlines to this model.</li><li>InlinesData: (<strong>Data</strong>) A place holder to store the data of the inlines.</li><li>Fields: A list of uadmin.F type representing the fields of the model.</li><li>IncludeFormJS: A list of string where you could add URLs to javascript files that uAdmin will run when a form view of this model is rendered.</li><li>IncludeListJS: A list of string where you could add URLs to javascript files that uAdmin will run when a list view of this model is rendered.</li><li>FormModifier: A function that you could pass that will allow you to modify the schema when rendering a form. It will pass to you the a pointer to the schema so you could modify it and a copy of the Model that is being rendered and the user access it to be able to customize per user (or per user group).</li><li>ListModifier: A function that you could pass that will allow you to modify the schema when rendering a list. It will pass to you the a pointer to the schema so you could modify it and the user access it to be able to customize per user (or per user group).</li></ul><p>The schema also has one method which is GetFieldByName() which allows you to get any uadmin.F object representing a field by name instead of searching for it in a the Fields list.</p><p>Now we will use this method to make one the description field required:</p><p>To do that, open main.go and add this code:</p><pre>import (<br>  &quot;github.com/twistedhardware/todo/models&quot;<br>  &quot;github.com/uadmin/uadmin&quot;<br>)<br>  <br>func main() {<br>  uadmin.Register(<br>    models.Todo{},<br>    models.Task{},<br>  ) <br>  uadmin.RegisterInlines(models.Task{}, map[string]string{<br>    &quot;Todo&quot;: &quot;TaskID&quot;,<br>  })</pre><pre>  <strong>// Modify Model Schema<br>  uadmin.Schema[&quot;todo&quot;].FieldByName(&quot;Description&quot;).Required = true</strong></pre><pre>  // Setup Email<br>  uadmin.EmailSMTPServer = &quot;smtp.gmail.com&quot;<br>  uadmin.EmailSMTPServerPort = 587<br>  uadmin.EmailFrom = &quot;TODO System &lt;<a href="/service/mailto:myemail@gmail.com">myemail@gmail.com</a>&gt;&quot;<br>  uadmin.EmailUsername = &quot;<a href="/service/mailto:myemail@gmail.com">myemail@gmail.com</a>&quot;<br>  uadmin.EmailPassword = &quot;my very hard password!&quot;<br> <br>  uadmin.SiteName = &quot;Todo App&quot;<br>  uadmin.StartServer()<br>  //uadmin.StartSecureServer(&quot;pub.pem&quot;, &quot;priv.pem&quot;)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*pe7ikpn1BP-hP9J7ik5EtA.png" /></figure><p>This will come is very handy once we go over uadmin.F in the next tutorial.</p><p>Congrats, now you understand the “magic” that makes uAdmin works which is the schema.</p><p>In the next part we will talk about field schema and explore what we can do with it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd2dd278b5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uAdmin the Golang Web Framework #9 Publishing]]></title>
            <link>https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-9-publishing-16ec1db7d4ac?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/16ec1db7d4ac</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-framework]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[hosting]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Wed, 14 Nov 2018 10:38:40 GMT</pubDate>
            <atom:updated>2018-12-06T12:43:01.898Z</atom:updated>
            <content:encoded><![CDATA[<h3>IMPORTANT (BEFORE YOU START)</h3><blockquote>If you installed uAdmin before November 14th <em>version 0.1.0-beta.4</em>, please update your uAdmin installation (<strong>If you are not sure, just update it anyway</strong>):</blockquote><pre>go get -u github.com/uadmin/uadmin/...</pre><blockquote>After you do that go to your project’s folder and run:</blockquote><pre>uadmin prepare</pre><blockquote>This will update uAdmin templates and static files.</blockquote><h3>Publishing Your App</h3><p>So far you have developed this really cool application that you want to show to your your customer or even to the world. Hosting Golang applications on a VPS or a dedicated server can be hard to setup and expensive. For development, you really don’t need this expensive setup. You just want your client to see your application for feedback. We offer FREE hosting for your app while you are developing.</p><p>A few limitations here:</p><ul><li>You have to make sure you application is using sqlite (which is the default DB in uAdmin)</li><li>Don’t use uadmin.StartSecureServer() you should only use uadmin.StartServer()</li><li>Don’t use this for doing anything illegal or for spam, hacking, pen-testing, DDoS … etc</li><li>Your application + data should not exceed 1GB</li><li>Daily bandwidth 5GB</li><li>Your application will expire in 24 hours if you didn’t publish anything new to it.</li><li><strong>PLEASE</strong> change your admin password after you publish your application or you will be putting your app and our servers at risk.</li></ul><p>That’s is. If you want to publish the application that you have been working on so far, make sure you return it to the old uadmin.StartServer().</p><p>Then go to your app’s folder and type:</p><pre>uadmin publish</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*IT974Z1-ZDpxcHjfmeekEQ.gif" /></figure><p>It will ask you for three fields:</p><ul><li><strong>Email</strong>: Your email</li><li><strong>Sub domain</strong>: The name of the sub domain that you want your application to be published to e.g. todo will publish it to <a href="https://todo.uadmin.io/">https://todo.uadmin.io</a>. You can just press Enter and it will generate a random domain name for you.</li><li><strong>Port</strong>: If you changed your port using uadmin.Port = X then provide the port that you used</li></ul><p>This way you can publish your application in ~1 minute and give access to your client or team to see your work and give you feedback.</p><p>If you need to update your application, just use the same command again:</p><pre>uadmin publish</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*t98lZPg352EzgMiRV4wTvw.gif" /></figure><p>Notice that the second time you you publish the same application it does that much faster. It only takes a few seconds the second time and it does not ask for any information about your app anymore. Every time you publish your app again, your app’s expiry is reset for 24 hours from your last publish.</p><p>You application is now live, you can access it using the URL you have at the end of uadmin publish output. We made sure you have SSL to protect your traffic to your app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*0-k09sG74okshBcIGyu3MQ.png" /></figure><p>You will now notice that you have a new file in your app’s folder .uproj which contains some information about your app.</p><pre>{&quot;domain&quot;:&quot;kr62&quot;,&quot;port&quot;:&quot;8080&quot;,&quot;uid&quot;:&quot;NfSD3qBsgwYdWlwei-okLQI&quot;}</pre><p>You should know that this is project specific data. User the data is available in your home directory in a file called .uadmin:</p><pre>{&quot;email&quot;:&quot;<a href="/service/mailto:abdullah@integranet.ph">abdullah@integranet.ph</a>&quot;,&quot;token&quot;:&quot;PW6wOdKGMZue0UfasffzR&quot;}</pre><p>This file contains your email which is to some level your username and your token which is kind of a password for your account. This way you can make sure your sub domains and your apps will not be overwritten by some else.</p><p>For now we don’t have a hosting service that holds applications for extended hosting (months or years). If you need to keep your app published for longer than 24 hours without publishing again, contact me email at abdullah@uadmin.io and I’ll extend your app’s expiry date for a week.</p><p>Hopefully soon we will setup the right servers to keep your application for longer and give you more storage and bandwidth and I’ll keep you posted regarding that.</p><p>Congrats you application is now live for the world to see. Share your cool apps with me and with others to see your creative work.</p><p>In <a href="https://medium.com/@twistedhardware/uaadmin-the-golang-web-framework-10-schema-basics-fd2dd278b5d">Part 10</a> we will talk about schema basics.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16ec1db7d4ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uAdmin The Golang Web Framework #8 Advanced Security]]></title>
            <link>https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-8-advanced-security-3c02f888a569?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c02f888a569</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[bcrypt]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ssl]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Tue, 13 Nov 2018 11:40:59 GMT</pubDate>
            <atom:updated>2018-11-14T11:02:35.987Z</atom:updated>
            <content:encoded><![CDATA[<h3>IMPORTANT (BEFORE YOU START)</h3><blockquote>If you installed uAdmin before November 13th <em>version 0.1.0-beta.3</em>, please update your uAdmin installation (<strong>If you are not sure, just update it anyway</strong>):</blockquote><pre>go get -u github.com/uadmin/uadmin/...</pre><blockquote>After you do that go to your project’s folder and run:</blockquote><pre>uadmin prepare</pre><blockquote>This will update uAdmin templates and static files.</blockquote><h3>Advanced Security</h3><p>There are many built in security features in uAdmin but we will talk about the most important features which are:</p><ul><li>SSL</li><li>2-Factor Authentication</li><li>Password Reset</li><li>Hash Salt</li><li>Database Encryption</li></ul><h3>SSL</h3><p>To enable SSL for your project, you need an SSL certificate. This is a two parts system with a public key and a private key. The public key is used for encryption and the private key is used for decryption. To get an SSL certificate, you can generate one using openssl which is a tool for generating self-signed SSL certificate.</p><pre>openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout priv.pem -out pub.pem</pre><p>It will ask you for several certificate parameters but you can just press “Enter” and skip filling them for development.</p><p>You can change the key size by changing 2048 to a higher value like 4096. For production, you would want to get a certificate that is not self-signed to avoid the SSL error message on the browser. For that, you can buy one from any SSL vendor or you can get a free one from <a href="https://letsencrypt.org/">letsencrypt.org</a>.</p><p>Once you have your keys, you can change your main.go like this:</p><pre>package main</pre><pre>import (<br>  &quot;github.com/twistedhardware/todo/models&quot;<br>  &quot;github.com/uadmin/uadmin&quot;<br>)</pre><pre>func main() {<br>  uadmin.Register(<br>    models.Todo{},<br>    models.Task{},<br>  )<br>  uadmin.RegisterInlines(models.Task{}, map[string]string{<br>    &quot;Todo&quot;: &quot;TaskID&quot;,<br>  })</pre><pre>  uadmin.SiteName = &quot;Todo App&quot;<br>  //uadmin.StartServer()<br>  uadmin.StartSecureServer(&quot;pub.pem&quot;, &quot;priv.pem&quot;)<br>}</pre><p>Notice that we commented uadmin.StartServer() and used uadmin.StartSecureServer(&quot;pub.pem&quot;, &quot;priv.pem&quot;) instead.</p><p>Once you start your app, you will notice that your terminal logs are showing a message that says https instead of http:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*Y6vJUzEZE4FD4SLqe4Q-dw.png" /></figure><p>When you open your app make sure that your URL uses https:// instead of http:// and you should get an error messag in your browser warning you that your SSL certificate could not be authenticated (because it is self-signed).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*IKkx3IcN1tIZjKCIjc3YHQ.png" /></figure><p>Proceed and you will see that your browser marks your URL in red to remind you that there is something wrong with your SSL certificate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*saVqC5OJamDl_Bp2qPaGqA.png" /></figure><h3>2-Factor Authentication</h3><p>It is also referred to as 2FA which is a way of using a OTP (One Time Password) for your login process to add an extra level of security to your account. uAdmin allows you to enable 2FA per user. To enable it for your account, open your profile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*aRrMGzRtQWEHtdPUQyjiQA.png" /></figure><p>On the left you will see a link that says “Enable 2-Factor Auth” click on that to enable 2FA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*KLm5UbycvK3EA6TfYV9I6Q.png" /></figure><p>Once you enable it, you will see your 2FA QR Code. You can use <a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2">Google Authenticator</a> to scan this code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*67PLlw43UHrkvVBibmNdfw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vOBvgRDK6UKeMEoXpVmMrw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ybERwKlbBnsDCZ8XEPeBpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y6AqeOinhkbAaENhE3s7vw.png" /></figure><p>Now log out and try to login again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*YlV394K7rBSpl4Iv2AYldQ.png" /></figure><p>Notice that you have a new field called “Verification Code” this is the number that you have in your Google Authenticator.</p><p>If you locked your self out and because of OTP, you can get your OTP from the terminal where you are running your application:</p><pre>[  INFO  ]   User: admin OTP: 621031</pre><h3>Password Reset</h3><p>For password reset to work you need to setup an email account that will send the password reset link. Also make sure that your user has an email in the system, otherwise they will not be able to reset their password. To setup an email account, you can use your gmail account or any SMTP account. Open your main.go and add these lines of code:</p><pre>import (<br>  &quot;github.com/twistedhardware/todo/models&quot;<br>  &quot;github.com/uadmin/uadmin&quot;<br>)<br>  <br>func main() {<br>  uadmin.Register(<br>    models.Todo{},<br>    models.Task{},<br>  ) <br>  uadmin.RegisterInlines(models.Task{}, map[string]string{<br>    &quot;Todo&quot;: &quot;TaskID&quot;,<br>  })</pre><pre>  // Setup Email<br>  uadmin.EmailSMTPServer = &quot;smtp.gmail.com&quot;<br>  uadmin.EmailSMTPServerPort = 587<br>  uadmin.EmailFrom = &quot;TODO System &lt;<a href="/service/mailto:myemail@gmail.com">myemail@gmail.com</a>&gt;&quot;<br>  uadmin.EmailUsername = &quot;<a href="/service/mailto:myemail@gmail.com">myemail@gmail.com</a>&quot;<br>  uadmin.EmailPassword = &quot;my very hard password!&quot;<br> <br>  uadmin.SiteName = &quot;Todo App&quot;<br>  //uadmin.StartServer()<br>  uadmin.StartSecureServer(&quot;pub.pem&quot;, &quot;priv.pem&quot;)<br>}</pre><p>Now run your app again and log out if you are still logged in and press “Forgot Password” from the login page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*MfV8y6aIYFe9szG7jEj4hA.png" /></figure><p>Enter your email:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*HCpwBCL8aK4EjmIpljItWg.png" /></figure><p>This will send you an email with a password reset link:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*PUcf2rHLcLhqAr7GHbvzHA.png" /></figure><p>Click on that and you will be able to reset your password:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*XSvei1fow-0neAdUrfT_lQ.png" /></figure><h3>Hash Salt</h3><p>All user passwords are hashed in the database. That means they are encrypted using a one way encryption meaning, your system does not know any user’s password. It actually encrypts the password again using the same algorithm and compares the two “hashes”. Bcrypt adds standard salt to your password to make it even more secure.</p><p>What happens when you get attacked and your database leaks into the Internet? We added one more level on security for you for this scenario. We create a file called .salt to your app’s folder which includes a 128 bytes of extra salt. This means doing any attack on your hashed passwords without knowing that long salt value is useless!</p><p>What about when the worst case scenario happens and both your database and your .salt file get hacked and leaked into the Internet. What can you do now to protect your system and yours? The answer is simple: just delete or rename your .salt file and run your system again and uAdmin will generate a new .salt file and create an emergency recovery user for you. This user does not have remote access so make sure you have access to your app from the same network before deleting your .salt file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*AapyB2_VoJKqFyMDUSftWw.png" /></figure><h3>Database Encryption</h3><p>You can keep your data in the database encrypted for any field. You might do that to protect some data or to comply with standards or fulfill client’s request. Let’s encrypt the name of our task model. To do that, open /models/task.go and add this tag to the Name fields:</p><pre>package models</pre><pre>import (<br>  &quot;github.com/uadmin/uadmin&quot;<br>)</pre><pre>type Task struct {<br>  uadmin.Model<br>  Name          string `uadmin:&quot;required;<strong>encrypt</strong>&quot;`<br>  TotalProgress int    `uadmin:&quot;progress_bar:30:red,70:yellow,100:green&quot;`<br>}</pre><p>Notice that you have to add encrypt tag to make this field encrypted in your database. Open your application and edit that field in any task you have and save:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*a8f-xTmZ_dXTm3tDnfGFUg.png" /></figure><p>When you check your database, you will notice that your data is encypted there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*RXdbHzY3EZq4PPN2ca4kmA.png" /></figure><p><strong>NOTE</strong>: encrypt tag only works with string fields</p><p>Congrats for finishing this long blog. Really I was seriously thinking of making this into two parts but I believed in you and if you are reading this part it means it was worth it.</p><p>In <a href="https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-9-publishing-16ec1db7d4ac">part 9</a> we will talk about publishing your app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c02f888a569" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uAdmin the Golang Web Framework #7 Logs]]></title>
            <link>https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-7-logs-b9f0542cdbf?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9f0542cdbf</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 14:47:01 GMT</pubDate>
            <atom:updated>2018-11-13T11:44:06.867Z</atom:updated>
            <content:encoded><![CDATA[<p>Your app by default keeps track of many things using the “Log” model. There are many types of logs that app records including:</p><ul><li><strong>Read</strong>: Opened a record</li><li><strong>Add</strong>: Saved a new record</li><li><strong>Edit</strong>: Save an existing record</li><li><strong>Delete</strong>: Deleted a record</li><li><strong>Login Successful</strong>: User login</li><li><strong>Login Denied</strong>: User invalid login</li><li><strong>Password Reset Request</strong>: A password rest was received</li><li><strong>Password Reset Successful</strong>: A password was rest</li><li><strong>Password Reset Denied</strong>: A password reset attempt was rejected</li><li><strong>Custom</strong>: For any other action that you would like to log</li></ul><p>Let’s open our app to see how these things work. Open your app and go to “LOGS” model in your dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*9Rj9qfcPKVB6o9tcXQ2Wew.png" /></figure><p>You will notice that you have logs for all the actions that you have taken in your app. If you open any of these logs, you will see all the details of that log:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*0-94kMgEZVt-jkPcSiI2Zg.png" /></figure><p>The activity is the main part of your log. This shows you what are the fields of your that you put in your record. It also adds one field for the IP &quot;_IP&quot; the user was using for security.</p><p>Edit and Delete logs will allow you to “Undo” them or “Roll Back” your changes.</p><p>To test that, I changed one of my todo records from 50 to 60:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*Flyk8FOvdvsFC48VnC1XLA.png" /></figure><p>Now If I go to “LOGS”, You will find the log of editing this record with the old value Progress: “50”. Click on “Roll Back”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*4z2nw7VbE1WLI6-chem6EQ.png" /></figure><p>Now go back to “TODOS” and you will see that your value changed back to 50:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*n3WzERs_p54KO3RC29GHlQ.png" /></figure><p>Logs can accumulate so fast and it will get harder to find specific actions when you need to like when conducting an audit and investigating something in your system. Use “Filter” to narrow down what you are looking for:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*_NxL2bJ6h2rjDQHkUVhrpQ.png" /></figure><p>These records can also be accessed from any record you have in your system. Notice that you have a “History” button when you open any record:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*nIa997iva_d9HJAm2_T6Zg.png" /></figure><p>This “History” button will give you logs related to this record:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*QvzaB60L3lpl_5fVBTSz3Q.png" /></figure><p>Congrats, now you know how to understand records you have in your app and how to audit them and revert back actions when you need to.</p><p>In <a href="https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-8-advanced-security-3c02f888a569">Part 8</a> we will talk about Advanced Security.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9f0542cdbf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uAdmin the Golang Web Framework #6 Authentication and Permissions]]></title>
            <link>https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-5-authentication-and-permissions-f3676a233a20?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3676a233a20</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Sat, 10 Nov 2018 14:14:17 GMT</pubDate>
            <atom:updated>2018-11-12T14:47:28.954Z</atom:updated>
            <content:encoded><![CDATA[<p>With the user model you can create new users and assign them to groups using the group model. Both user and group can be assigned permissions to access parts of your system. By default the system creates one user which is the admin user who has full permission to read, add edit and delete data from every model. So let’s create a new user in the system.</p><p>To do that, go to “USERS” model in your dashboard and create a new user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*fbWIfDg-o7yk9rFmmPw3oA.png" /></figure><p>Notice the the password field is masked and you should click on the blue button to show it’s content. Don’t worry your password will be be saved in the DB in clear text. It will be hashed using <a href="http://bcrypt.sourceforge.net/">bcrypt</a> with fairly high level of difficulty (It almost take 500ms to hash the password). Also, make sure that you made the user “Active” or you will not be able to login with that user.</p><p>Finally, the user should be able to access the app remotely, then check “Remote Access”. If it is not checked, you will only be able to login if you are connected to the server using a private IP e.g. (10.x.x.x,192.168.x.x, 127.x.x.x or ::1)</p><p>Now save your use and logout. then login with the new username. Notice that we don’t have access to any dashboard models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*5U2GJBoLvwnrW69EKeeEVA.png" /></figure><p>Let’s give our user some permissions. First, logout and login again as admin. then go to the new user and open the second tab “USER PERMISSION”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*u8EmR1g8yElQuI2dmHf-7w.png" /></figure><p>Add a few permissions to your user:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*zi9RzWPtT-dm6DT4cmFhaQ.png" /></figure><p>Logout and login again with the new user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*2X5IPKf9-J1-f21AmAGQ4A.png" /></figure><p>Notice that you have now access to the models that you have permission to. Logout and login again as admin. Now go to “USER GROUPS” and add a new group. After you save it, go to the second tab “GROUP PERMISSION” and add a new permission that you don’t have in the user level and only check “Read”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*geOENcEXxZq4kSOSWosxSw.png" /></figure><p>Notice that your group has Read only access to log. Add your user to the new group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*AbPW95oWCCsLv8GBb4wYHw.png" /></figure><p>Logout and login again with your user and notice that you have now access to the models from your user and from your group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*RxyBakL0ORUJ2ahnYHzQLg.png" /></figure><p>By default you get permission to all the models that your group has permission to. Your user permissions override these in case of a model existing in group permissions and user permissions. To test that give your user Add, Save and Delete to the model that your group has Read only access. (You have to do that from admin)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*V9D4YqN6wckLBDadLPNBeQ.png" /></figure><p>Now log in again with your user and check that you have full access to this model even when your group has Read only access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*VXkUv0cAQnVj3_qpIbwfJA.png" /></figure><p>You can also use that to give the user less permission than what the group is giving them. Go back to admin and uncheck Read, Add, Edit and Delete from the model that your group has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*JA5VdgT8K4q-9hlbUXP8ug.png" /></figure><p>Login in again with your user and notice that you lost your permission to access the model that your group has access to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*GOmZgmzbMkLQBXiHe0dQIA.png" /></figure><p>Congrats, you now know how to:</p><ul><li>Manage users and groups</li><li>Customize group permissions</li><li>Override group permission with user permissions</li></ul><p>In <a href="https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-7-logs-b9f0542cdbf">part 7</a>, we will talk about Logs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3676a233a20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uAdmin the Golang Web Framework #5 Validation]]></title>
            <link>https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-5-validation-3a45ac20a9c5?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a45ac20a9c5</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Wed, 07 Nov 2018 17:21:28 GMT</pubDate>
            <atom:updated>2018-11-10T14:17:24.275Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>IMPORTANT (BEFORE YOU START)</strong></h3><blockquote>If you installed uAdmin before November 7th version 0.1.0-alpha, please update your uAdmin installation (<strong>If you are not sure, just update it anyway</strong>):</blockquote><pre>go get -u github.com/uadmin/uadmin/...</pre><blockquote>After you do that go to your project’s folder and run:</blockquote><pre>uadmin prepare</pre><blockquote>This will update uAdmin templates and static files.</blockquote><h3>Front-End Validation</h3><p>Validation for user input in uAdmin can be done in front-end and back-end. There are a few things that we can validate depending in the field data type.</p><p>First validation is required which works on all data types. Let’s make a few fields required in out app. Open /models/todo.go and make both Name and TargetDate required.</p><pre>type Todo struct {<br>  uadmin.Model<br>  Name        string     `uadmin:&quot;required&quot;`<br>  Description string     `uadmin:&quot;html&quot;`<br>  TargetDate  *time.Time `uadmin:&quot;required&quot;`<br>  Progress    int        `uadmin:&quot;progress_bar:30:red,70:yellow,100:green&quot;`<br>  Task        Task<br>  TaskID      uint<br>}</pre><p>Compile and run your app again:</p><pre>$ go build; ./todo</pre><p>When you open a todo record you will see that both fields are required:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*lm5Y4IkCpaoWJzFDEnkDuw.png" /></figure><p>Notice there is a red asterisk to required fields and if you try to save without filling a required field, it will ask you to fill the field first.</p><p>Next is max and min validations and these work for numeric fields. I want to limit my progress between 0–100. The way I can do that is to add these validations as a tags to Progress field in /models/todo.go.</p><pre>type Todo struct {<br>  uadmin.Model<br>  Name        string     `uadmin:&quot;required&quot;`<br>  Description string     `uadmin:&quot;html&quot;`<br>  TargetDate  *time.Time `uadmin:&quot;required&quot;`<br>  Progress    int        `uadmin:&quot;progress_bar:30:red,70:yellow,100:green;min:0;max:100&quot;`<br>  Task        Task<br>  TaskID      uint<br>}</pre><p>Notice that you can add more tags inside your uadmin tag by separating them with a semicolon. In Progress we have now three tags, progress_bar, min and max. Not compile and run again and you will notice that you cannot put any values outside of that range (0–100).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*pSMjejNdp47VFsRnFvRLPw.png" /></figure><p>Next is pattern which is the most powerful front-end validation tag which works for string fields. The way it works is using <a href="https://regexr.com/">Regular Expression</a>. Let’s add a validation for Name fields in /models/todo.go to limit the number of letters in the name to 5–100 letters. We can add an optional message with that validation which using pattern_msg tag. To do that open /models/todo.go and add this tag:</p><pre>type Todo struct {<br>  uadmin.Model<br>  Name        string     `uadmin:&quot;required;pattern:.{5,100};pattern_msg:Name length should be 5-100 letters&quot;`<br>  Description string     `uadmin:&quot;html&quot;`<br>  TargetDate  *time.Time `uadmin:&quot;required&quot;`<br>  Progress    int        `uadmin:&quot;progress_bar:30:red,70:yellow,100:green;min:0;max:100&quot;`<br>  Task        Task<br>  TaskID      uint<br>}</pre><p>Now compile and run again and you will get extra validation for the Name fields:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*yxpMyXJGmaE_jv6se9dJyg.png" /></figure><h3>Back-end Validation</h3><p>For more advanced validation, sometimes you need to implement some validation from the back-end. This is the case for validation that required access to the database to check for duplicate entries or check some permissions like “<em>You are not allowed to assign this task to people outside your department</em>”. Regardless of the case this is how to implement back-end validation.</p><p>let’s say we don’t want people to add duplicate entries for todo. The way we will do that is check the database and see if there is another todo record with the same name. If we find another record, we can return a message that tells the user that the todo item has been added to the system already.</p><p>Open /models/todo.go and add a new method called Validate to your Todo struct.</p><pre>type Todo struct {<br>  uadmin.Model<br>  Name        string     `uadmin:&quot;required;pattern:.{5,100};pattern_msg:Name length should be 5-100 letters&quot;`<br>  Description string     `uadmin:&quot;html&quot;`<br>  TargetDate  *time.Time `uadmin:&quot;required&quot;`<br>  Progress    int        `uadmin:&quot;progress_bar:30:red,70:yellow,100:green;min:0;max:100&quot;`<br>  Task        Task<br>  TaskID      uint<br>}</pre><pre>func (t *Todo) Save() {<br>  // Save the model to DB<br>  uadmin.Save(t)</pre><pre> // Some other business Logic ...<br>}</pre><pre>func (t Todo) Validate() (errMsg map[string]string) {<br>  // Initialize the error messages<br>  errMsg = map[string]string{}</pre><pre>  // Get any records from the database that maches the name of<br>  // this record and make sure the record is not the record we are<br>  // editing right now<br>  todo := Todo{}<br>  if uadmin.Count(&amp;todo, &quot;name = ? AND id &lt;&gt; ?&quot;, t.Name, t.ID) != 0 {<br>    errMsg[&quot;Name&quot;] = &quot;This todo name is already in the system&quot;<br>  }<br>  return<br>}</pre><p>Notice that the receiver for Validate() is not a pointer but the struct type. Also notice that the return is a map where the key is the field name and the value is the error message.</p><p>If you try now to add a new record with an existing todo record’s name, it will show me this error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*QkvmGGa8GJuYBt3Dk4u1SQ.png" /></figure><p>Congrats, you have understand now how to validate user input from the front-end and the back-end.</p><p>In <a href="https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-5-authentication-and-permissions-f3676a233a20">Part 6</a>, we will authentication and permissions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a45ac20a9c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uAdmin the Golang Web Framework #4 Customizing Dashboard]]></title>
            <link>https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-4-customizing-dashboard-d96d90792a07?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d96d90792a07</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Tue, 06 Nov 2018 09:16:18 GMT</pubDate>
            <atom:updated>2018-11-07T17:22:09.622Z</atom:updated>
            <content:encoded><![CDATA[<p>The dashboard of your app is the first impression that users will get from your app. Making it look good and customizing it to meet your customers requirements is important to the success of your app. We will start by adding icons to your the models that you already added to your dashboard.</p><p>To do that open “DASHBOARD MENU”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*XcmUmnp8Y7JcLSH3Ddmjlw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*WDQlCFgcOEGsutYy3WpS8Q.png" /></figure><p>Open “Tasks” and search for an icon that you like to add to your dashboard to represent a task. By default any model that does not have an icon gets this icon:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*T9z3JSP7iAM_X6ay28Qrzw.png" /></figure><p>I would suggest you find an icon from <a href="http://www.flaticon.com/">flaticon.com</a> to keep the style of the dashboard, but feel free to change the style and make it yours. If you are getting your icon from <a href="http://www.flaticon.com/">flaticon.com</a>, search for an icon and download the PNG version and choose the size 128 pixels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*uJzHdcSlC62qZMt2kTUQ5g.png" /></figure><p>Now that you have downloaded your icon, you add add it to “Task” in “DASHBOARD MENU” and Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*uE4moGGUnnJQb9ffqNBvaw.png" /></figure><p>You should be able to see the icon in the list view of your “DASHBOARD MENU”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*JIlln3cbPCIwfPl6fFv0MQ.png" /></figure><p>Go back to your dashboard and see your model’s new icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*p6vQMSLLQSKBhdw2XWEqhA.png" /></figure><p>Now do that same thing to “TODOS” and find an icon that you like for that one.</p><p>Once we are done with icons, let’s activate another language in uAdmin. To do that, go to “LANGUAGES” and find a any language that you like to activate besides English which is a activated already. For me I’ll activate the “Arabic” language (since it is my first language). To do that open “LANGUAGES” then use the search to find your language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*TgtFbdrG04GfDSTA7DynLQ.png" /></figure><p>Now open that language and change “Active” to true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*8f-VOMoIAIp_0pZACHs6VQ.png" /></figure><p>For now don’t worry about these other toggle boxes, just change “Active” to true and Save.</p><p>Go back to your dashboard and open “DASHBOARD MENU” and open “Tasks” and you will see that your “Name” field has two fields inside it, one for English and one for Arabic. Notice that the Arabic one has a red “X” next to it indicating it is not translated yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*SLYRqyjcJXMSWX0dotyHPw.png" /></figure><p>Enter the name of the model in your language. In Arabic Tasks is “المهام”.</p><p>Save your model and notice that the Arabic name has turned green showing it is translated already.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*Glralb6dgfiZuDvPFxtU_Q.png" /></figure><p>To switch your language, logout and login again and change the language to Arabic during login.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*Ij1TqIhwFgu80a9Lxwding.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*suDYG7yWDdnQV7Dmk7SbRA.png" /></figure><p>Notice it your dashboard that “TASKS” is translated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*YYZyWYOaXPIZyhH01nl6eQ.png" /></figure><p>Now we will stop our add and start it again, and you will see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*DGffltUEG9pNFa3aFbkBNg.png" /></figure><p>It is giving you a warning saying that you didn’t translate your models into the newly activated language “Arabic”. To do that look in your project path and you will see a folder named /static/i18n/ which includes automatically generated files for all activated languages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*ewDolQ65IzXvGIq-z_ignQ.png" /></figure><p>you will see three folders under /static/i18n/:</p><ul><li>main: is not important because this was automatically generated before you moved our models to models package.</li><li>models: is your the folder with your app models</li><li>uadmin: is uAdmin system models</li></ul><p>Open /static/i18n/models/task.ar.json and you will get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*izGGiLMvYlFiidjDJ48aAA.png" /></figure><p>Any field that starts with Translate me ---&gt; should be translated. After translating my file, now it looks like this:</p><pre>{<br>  &quot;display_name&quot;: &quot;المهام&quot;,<br>  &quot;fields&quot;: {<br>    &quot;ID&quot;: {<br>      &quot;display_name&quot;: &quot;ID&quot;,<br>      &quot;help&quot;: &quot;&quot;,<br>      &quot;pattern_msg&quot;: &quot;&quot;,<br>      &quot;err_msg&quot;: {},<br>      &quot;Choices&quot;: null<br>    },<br>    &quot;Name&quot;: {<br>      &quot;display_name&quot;: &quot;الاسم&quot;,<br>      &quot;help&quot;: &quot;&quot;,<br>      &quot;pattern_msg&quot;: &quot;&quot;,<br>      &quot;err_msg&quot;: {},<br>      &quot;Choices&quot;: null<br>    },<br>    &quot;TotalProgress&quot;: {<br>      &quot;display_name&quot;: &quot;إجمالي الانجاز&quot;,<br>      &quot;help&quot;: &quot;&quot;,<br>      &quot;pattern_msg&quot;: &quot;&quot;,<br>      &quot;err_msg&quot;: {},<br>      &quot;Choices&quot;: null<br>    }<br>  }<br>}</pre><p>Save your file and run your app again and you will get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*FPEt7v8nSOtJLZTMVY_jWQ.png" /></figure><p>uAdmin has found the 4 words we translated and is telling us we are at 3% translation for the Arabic language. We can translate each file and get this to 100% to make the warning message go away. This good thing is this can be done during development and ad you add new fields they will be added to your active language and it will keep track of what is currently translated you work on development.</p><p>Login again in “Arabic” and check your “TASKS” and you will get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*lQc9Tw5_FB_gCrbo-zu8uA.png" /></figure><p>Congrats. This was a code-free tutorial but we got so much done without writing a single line of code:</p><ul><li>Customize dashboard models with icons</li><li>Activate other languages</li><li>Translate your model name in other languages</li><li>Translate your model field names in other language</li></ul><p>In the <a href="https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-5-validation-3a45ac20a9c5">part 5</a>, we will talk about validation server-side and client-side.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d96d90792a07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uAdmin the Golang Web Framework #3 Business Logic]]></title>
            <link>https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-3-business-logic-e2671c02e42?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2671c02e42</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Mon, 05 Nov 2018 16:51:31 GMT</pubDate>
            <atom:updated>2018-11-06T12:20:15.045Z</atom:updated>
            <content:encoded><![CDATA[<p>Wouldn’t be cool if you can access your todo items directly from your task? well this is exactly what inlines are for. We will register an inline for task to add a list of related todo to it. Open your main.go and edit it to look like this:</p><pre>package main</pre><pre>import (<br>  &quot;github.com/uadmin/uadmin&quot;<br>  &quot;github.com/your_name/todo/models&quot;<br>)</pre><pre>func main() {<br>  uadmin.Register(<br>    models.Todo{},<br>    models.Task{},<br>  )<br>  uadmin.RegisterInlines(models.Task{}, map[string]string{<br>    &quot;Todo&quot;: &quot;TaskID&quot;,<br>  })<br>  uadmin.SiteName = &quot;Todo App&quot;<br>  uadmin.StartServer()<br>}</pre><p>Notice the uadmin.RegisterInlines function that we added. It receives a model as the first parameter and the second parameter is a map[string]string where the key of the map is the name of the related model and the value is the uint field for that relation. You can add multiple inlines if you have multiple relationships that you want to link to a model.</p><p>Now run your app again and you should see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*mMZgBxQ5ufAKnfi-5RpcPg.png" /></figure><p>Notice the second tab called “TODO”. If you open it you will see a table with all related todo items to this task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*E-N8DV4ajH1i51OjyEREmA.png" /></figure><p>From this table you can add new todo items directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*MQihI8rqT1EiR_1QcT30vg.png" /></figure><p>Notice that the task is pre-selected for you so you can fill the other fields and save and it will return you to the same task you were in.</p><p>Now let’s add some business logic to our app. I would like to calculate the progress of my task based on the progress of the child todo items. Now to do that, I will need to get all the todo items from the database that is linked to my task and get the average progress from all of them and update my task. Since this is going to change when we change a todo we need to add this business logic in todo. To do that, we will override the Save() method of todo. Open /models/todo.go and add this method:</p><pre>package models</pre><pre>import (<br>  &quot;github.com/uadmin/uadmin&quot;<br>  &quot;time&quot;<br>)</pre><pre>type Todo struct {<br>  uadmin.Model<br>  Name        string<br>  Description string `uadmin:&quot;html&quot;`<br>  TargetDate  *time.Time<br>  Progress    int `uadmin:&quot;progress_bar&quot;`<br>  Task        Task<br>  TaskID      uint<br>}</pre><pre>func (t *Todo) Save() {<br>  // Save the model to DB<br>  uadmin.Save(t)</pre><pre>  // Get a list of other todo items that share the same<br>  // TaskID. Notice that in the filter we use task_id which<br>  // is the way this is created in the DB<br>  todoList := []Todo{}<br>  uadmin.Filter(&amp;todoList, &quot;task_id = ?&quot;, t.TaskID)<br>  progressSum := 0<br>  progressCount := len(todoList)</pre><pre>  // Sum up the progress of all tasks<br>  for _, todo := range todoList {<br>    progressSum += todo.Progress<br>  }</pre><pre>  // Preload the todo model to get the related task<br>  uadmin.Preload(t)</pre><pre>  // Calculate the average progress<br>  t.Task.TotalProgress = progressSum / progressCount</pre><pre>  // Finally save the task<br>  uadmin.Save(&amp;t.Task)<br>}</pre><p>Now go ahead and add a few todo items and make sure they point to your task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*S5o1jtPubvOfNipODajOTg.png" /></figure><p>Notice now that your task is updating its progress automatically</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*nUQv5xBXwnRlGdNQh3WVRg.png" /></figure><p>Finally, let’s make this customize our progress bar. I would like to make it show different colors depending on progress:</p><ul><li>Red: 0–30</li><li>Yellow: 31–70</li><li>Green: 71–100</li></ul><p>The way we can do that is by customizing the progress_bar tag. We can add these thresholds like this progress_bar:30:red,70:yellow,100:green. Let’s do that to both progress bars in todo and task.</p><p>In /models/todo.go, change the field Progress with this line:</p><pre>Progress int `uadmin:&quot;progress_bar:30:red,70:yellow,100:green&quot;`</pre><p>In /models/task.go, change the field TotalProgress with this line:</p><pre>TotalProgress int `uadmin:&quot;progress_bar:30:red,70:yellow,100:green&quot;`</pre><p>Run your app again and you will get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*v26gNRSqQhofev06ccDRhg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*H9i40Tew5k2Px3e14jj4Wg.png" /></figure><p>Congrats, you know how do the following:</p><ul><li>add inlines</li><li>use uadmin.Filter to get records from your database</li><li>add business logic by overriding Save() method</li><li>you have mastered the progress_bar tag.</li></ul><p>In <a href="https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-4-customizing-dashboard-d96d90792a07">part 4</a>, we will talk about customizing your dashboard.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2671c02e42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uAdmin the Golang Web Framwork #2 Managing Your Models]]></title>
            <link>https://medium.com/@twistedhardware/uadmin-the-golang-web-framwork-2-managing-your-models-22699db7dc92?source=rss-3a7cc5881c2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/22699db7dc92</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Abdullah Alrasheed]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 04:21:09 GMT</pubDate>
            <atom:updated>2018-11-06T12:19:49.716Z</atom:updated>
            <content:encoded><![CDATA[<h3>uAdmin the Golang Web Framework #2 Managing Your Models</h3><p>In <a href="https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-a666651479af">part one</a> of this tutorial, I cheated to make my blog post shorter by putting my model inside main.go which is not a good idea. Think about how would your project look like when you have 50 models and business logic all jammed inside main.go with over 3K lines of code in one file. To make this scalable, we could add our models inside the models folder and each model should be a separate file. Let’s fix that by adding a file named todo.go under models:</p><pre>todo/<br>    models/<br>        todo.go<br>    main.go</pre><p>Now in this file we will put the following code:</p><pre>package models</pre><pre>import (<br>  &quot;github.com/uadmin/uadmin&quot;<br>  &quot;time&quot;<br>)</pre><pre>type Todo struct {<br>  uadmin.Model<br>  Name        string<br>  Description string `uadmin:&quot;html&quot;`<br>  TargetDate  time.Time<br>  Progress    int `uadmin:&quot;progress_bar&quot;`<br>}</pre><p>Now we can edit out main.go and remove the model from there and add a reference to the new todo model.</p><pre>package main</pre><pre>import (<br>  &quot;github.com/uadmin/uadmin&quot;<br>  &quot;github.com/your_name/todo/models&quot;<br>)</pre><pre>func main() {<br>  uadmin.Register(models.Todo{})<br>  uadmin.SiteName = &quot;Todo App&quot;<br>  uadmin.StartServer()<br>}</pre><p>Notice that we have to import the models package and refer to our model using models.Todo. Also we did some customization to make the app ours by changing the variable uadmin.SiteName which controls the website name on uAdmin’s UI.</p><p>Now you can run your project again:</p><pre>$ go build; todo<br>[   OK   ]   Initializing DB: [9/9]<br>[   OK   ]   Server Started: <a href="http://0.0.0.0:8080/">http://0.0.0.0:8080</a><br>         ___       __          _<br>  __  __/   | ____/ /___ ___  (_)___<br> / / / / /| |/ __  / __ &#39;__ \/ / __ \<br>/ /_/ / ___ / /_/ / / / / / / / / / /<br>\__,_/_/  |_\__,_/_/ /_/ /_/_/_/ /_/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*uS18ghlaKPCo6CWgGz_1BA.png" /></figure><p>Notice the name on your dashboard and in the title in your browser. We will get to more customization in following parts of this tutorial but for now lets do one more thing, let’s add one more model to our project. The new model will be a larger scope model called task which will have a list of todo. Think of task like a project and todo is a specific thing that you have to do in that project. So each todo has a task and a task could have many todo items (in technical terms one-to-many relationship). The way we do that is, create the new model as a new file called task.go in models folder:</p><pre>todo/<br>    models/<br>        task.go<br>        todo.go<br>    main.go</pre><p>In the new file, add the following code:</p><pre>package models</pre><pre>import (<br>  &quot;github.com/uadmin/uadmin&quot;<br>)</pre><pre>type Task struct {<br>  uadmin.Model<br>  Name          string `uadmin:&quot;required&quot;`<br>  TotalProgress int    `uadmin:&quot;progress_bar&quot;`<br>}</pre><p>Notice that we added a tag called required in the Name field. that will make it required and stop users from saving tasks with no name.</p><p>Now let’s edit our todo model and add a foreign key to task. Don’t let the technical terms like “foreign key” scare you, it is just a link from one model to another model (you will get it in a second). Now edit todo.go like this:</p><pre>package models</pre><pre>import (<br>  &quot;github.com/uadmin/uadmin&quot;<br>  &quot;time&quot;<br>)</pre><pre>type Todo struct {<br>  uadmin.Model<br>  Name        string<br>  Description string `uadmin:&quot;html&quot;`<br>  TargetDate  time.Time<br>  Progress    int `uadmin:&quot;progress_bar&quot;`<br>  Task        Task<br>  TaskID      uint<br>}</pre><p>That’s it! that is how you add a foreign key. Add two fields to your struct, one of the type of the other model and one using the same name followed by ID and type uint.</p><p>Now you have to register your new model to uAdmin. To do that, edit your main.go to look like this:</p><pre>package main</pre><pre>import (<br>  &quot;github.com/uadmin/uadmin&quot;<br>  &quot;github.com/your_name/todo/models&quot;<br>)</pre><pre>func main() {<br>  uadmin.Register(<br>    models.Todo{},<br>    models.Task{},<br>  )<br>  uadmin.SiteName = &quot;Todo App&quot;<br>  uadmin.StartServer()<br>}</pre><p>now let’s run your project and see what we have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*imaOcpqel27q5e3NFnXEDA.png" /></figure><p>Notice that we have a new model in the dashboard called “Tasks”. Let’s add a task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*groO-qWIcC2sYw2MbbdtsQ.png" /></figure><p>Now you can link a todo to your task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2o4SUUqjOmxSO7FVjiSfuw.png" /></figure><p>Now notice that you can see it in the list view after you save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMiwRiRGQCMzNs1_R2ev-g.png" /></figure><p>Congrats, you know now how to manage your models and scale your project to a large scale project using models and how to use foreign keys.</p><p>In the <a href="https://medium.com/@twistedhardware/uadmin-the-golang-web-framework-3-business-logic-e2671c02e42">next part</a> we will talk about inlines, business logic and more customization using tags.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22699db7dc92" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>