Creating a JWT secured react app and Kotlin server (part 2)

Time for some code at last! If you haven’t read my last post, please head on back here.

I’m starting things off with a very simple controller that returns HTML responses.

package com.chrisyoung.auth

import org.springframework.http.MediaType
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.ui.set
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestParam


@Controller
class LoginController {
    @GetMapping("/login")
    fun loginForm(model: Model): String {
        model["title"] = "Login"
        return "login"
    }
    @PostMapping("/login", consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE])
    fun login(
            model: Model,
            @RequestParam(name = "username") username: String,
            @RequestParam(name = "password") password: String
    ): String {
        model["title"] = "Login"
        model["username"] = username;
        model["password"] = password;
        return "loggedin"
    }
}

Annotations are extremely powerful in Spring Boot. The @Controller, @GetMapping and @PostMapping annotations are taking care of the routing and request and response handling for us. I admit that they do seem a little bit too magical, but I’ve always enjoyed a bit of magic over a bunch of boilerplate.

in the functions we can see the beautiful strictly typed parameters, including the special parameter “Model” used by the mustache templates below

The application is very simple at this point. The /login route displays a html form with fields for username and password, and when that is submitted, those values are pulled out of the form-encoded request into String-type function parameters which are just displayed on the next page. I’m not actually implementing any login logic here, just request logic. I haven’t started with REST endpoints yet, because I need a couple of actual HTML pages in my auth service for the initial login and the authorisation page.

I also need a couple of templates named to match the return values of the GET and POST mapping above

{{>_header}}
    <h1>Login</h1>
    <form method="POST" action="/login">
        username:
        <input type="text" name="username"/>
        <br />
        password:
        <input type="password" name="password"/>
        <br />
        <input type="submit" title="login"/>
    </form>
{{>_footer}}

/resources/templates/login.mustache

{{>_header}}
<h1>Logged in</h1>
<p>username {{username}}</p>
<p>password {{password}}</p>
{{>_footer}}

/resources/templates/loggedin.mustache

Next I’ll add a bit of logic to make it a bit more functional
Continue Reading…

Photographing a walk in the woods

I was delighted yesterday to go for a walk in one of the most beautiful places I’ve ever been. Aira Force is a waterfall in the Lake District in the North of England. I must say it was breathtaking. A great way to spend a Saturday afternoon.

VLUU P1200  / Samsung P1200

I would have taken my Sony DHC-HX1 semi pro camera on such an excursion but – as so often happens – I pulled it out of the case to find it had no charge left. I guess you just need to leave the battery on trickle-charge and take it out when you want to use it.

Anyway I ended up taking a lot of photos with my Galaxy S3. I’ve never been a fan of smartphone cameras for hobby photography, but to be honest taking photos with this phone was really fun. The colour reproduction and lighting were fantastic, and the camera is so clever that you barely have to touch the controls. Yes, I missed having 20x optical zoom (the S3 has nothing) but there was plenty to take in without zoom.

 

20130209_150522

20130209_152552

One design flaw I’ve found about Android phones is that whilst there is now a shortcut to the camera on the lock screen, launching it still requires you to unlock the phone to use it – I believe the iPhone 5 allows you to use the camera without unlocking the phone – this means my wife is already taking photos of that amazing thing while I’m still fiddling with my phone.

But, why complain? The S3 did a fantastic job and meant I didn’t have to haul around my big camera on such a lovely expedition.

20130209_151153

Start here

I’ve decided to re-start my own personal blog page so that I can write about cool things that I discover, hacks that I figure out and problems that I solve. Also I’ll probably complain about lots of little amusing things. This blog will be less ministry-update-dinner and more random-thoughts-and-ideas. My wife and I will still maintain our ministry blog at http://www.youngfam.net/ weekly and we encourage you to read it to stay up do date with what God is doing in our lives here in Carlisle.

My calling to work with kids in mission

At my desk

Having spent a significant portion of my childhood as an MK (missionary kid) I developed a strong awareness and interest in mission work which stayed with me into adulthood, although I never had any plans or ideas where this would take me. By the age of 5 I’d chosen my career path and this finally came true in 2004 when I qualified as a primary school teacher. These two passions have always been present in my life to varying degrees. Throughout university and my years teaching in the UK I went on several short term mission trips and was involved with the mission team at my church.

In 2008 I finally felt the time to serve longer term in mission was approaching. For me it was an obvious and easy decision to teach MK’s as this combined my own experiences, passion for mission and love of teaching. Eventually I ended up on Logos Hope, as a teacher in the school onboard. Amongst the 400 crew onboard there are usually about 40 children, aged from 0 – 16. The school usually has about 8 teachers who provide an education for these children during their time onboard.

Having taught in the school on Logos Hope for 2 years I returned to the UK in October 2011, again wondering how all my passions and experiences could be combined. Through a series of thoughts and conversations God has led me to take on the role of ‘Family and Educational Support Advisor’ with OM.

Part of this role is to ensure that families and children on the mission field are well cared for, receiving the support and advice that they need to raise their family, make educational choices and deal with the unique challenges they face. This means providing resources, support and advice at all stages of their journey: as the plan and prepare for the mission field, during their time overseas and as they re-enter their home country. Having been an MK myself I can understand some of both the positive and negative impacts that can occur and I hope to be able to help maximise the former and minimise the latter.

Another part of the role is recruiting and supporting teachers, especially for the ship school. Recruitment is something totally new for me but having been a teacher onboard the ship I have some understanding of how to support them effectively. This includes being available to answer questions, providing resources and ensuring they are kept up to date with the curriculum.

Successfully fulfilling this role will require a lot of networking; researching about MKs, attending conferences and liaising with OM offices around the world. One person described the need for someone to be a ‘children’s advocate’ and I guess in many ways that is what I am hoping for – that I will be able to speak up on behalf of the children involved in mission and ensure that their needs are remembered by all involved.
All of this will be a part time role. In many ways stepping out of the classroom and into an office is a daunting prospect but I feel that my experiences all add up to help me face this new challenge. And to make sure I don’t go completely insane through a lack of interaction with children I hope to be able to teach part time. This will have the added benefit of enabling me to keep up with the changes to the curriculum.  At the moment I have no idea what this teaching job may actually look like but am trusting that God has something lined up for me and will reveal it at the right time.

What does it mean to be a Christian?


What does it mean to be a Christian? Is it about doing good, living by the rules of a religion? Is it about filling in time here on earth while waiting for our ascent into heaven? There must be something more. Surely we have a purpose in this life beyond making money, sleeping, working and dying.

Something we really need to understand about the world is that, yes God loves us – but it’s not about God loving us at all. It’s about God. Everything is about God. He is the Alpha and the Omega, The beginning and the end and without him nothing that exists has come into being. The story the universe and therefore the meaning of life, the universe and everything is all about God, and we are his treasured creations.

We have been given life by God’s breath and whilst we have made a mess of our world, He has given us quite an amazing planet to live on. God is worthy of worship, it’s quite simple. He created the stars – do you have any idea how massive the universe is, how complex every star and planet, how intricate the human body? God is amazing! And every person on this earth should give him the glory for the great things he has done.

God’s desire

God is really keen to make contact with the rest of the world, but he’s not about to force himself on people like a dictator. Check out Ezekiel 36:22-23: “…It is not for your sake, O house of Israel, that I am going to do these things, but for the sake of my holy name… I will show the holiness of my great name … Then the nations will know that I am the LORD, declares the Sovereign LORD, when I show myself holy through you before their eyes.” (my emphasis added). And Habakkuk 2:14

“For the earth will be filled with the knowledge of the glory of the LORD, as the waters cover the sea.”.

Abraham

His plan to reach the nations through people started with Abraham: Take a look at Genesis 12: 2-3:

I will make you into a great nation
       and I will bless you;
       I will make your name great,
       and you will be a blessing.

I will bless those who bless you,
       and whoever curses you I will curse;
       and all peoples on earth
       will be blessed through you.

This promise of God to bless Abraham and his descendants is given with the intention that Abraham and his descendants would bless all the peoples of the earth. We see also in Ezekiel 36 that God wants to use Israel to make his name known all over the earth, even though they had not done so well so far.

Blessings today

This blessing extends to us today. In Galatians 3:8-9 the author states “The Scripture foresaw that God would justify the Gentiles by faith, and announced the gospel in advance to Abraham: “All nations will be blessed through you.” So those who have faith are blessed along with Abraham, the man of faith.” and in Acts 3:25-26: “You are really the ones God told his prophets to speak to. And you were given the promise that God made to your ancestors. He said to Abraham, “All nations on earth will be blessed because of someone from your family.” God sent his chosen Son to you first, because God wanted to bless you and make each one of you turn away from your sins.”

That’s fantastic! The blessing is given to us non-Jewish follows of Christ as well, but why? So that we may be a blessing to others. We cannot simply accept that God has blessed us without accepting the second part of the statement in Genesis 12:2 that commands us to be a blessing to others.

Our mission

So how are we to be a blessing to others and make God’s name great thought the earth. Jesus makes it clear in Matthew 28: 19: “Go and make followers of all people in the world. Baptize them in the name of the Father and the Son and the Holy Spirit.”. Our mission is clear, we need to get about the business of sharing the great news of Jesus Christ with people from all over the world. Not all of us need to go overseas and preach, but all of us need to play a part in this task. For this is both the desire of God and the revealed destiny of the church.

And they sang a new song:
   “You are worthy to take the scroll
      and to open its seals,
   because you were slain,
      and with your blood you purchased men for God
      from every tribe and language and people and nation. (Rev 5:9)

Timeless hymns

I heard an ad on the radio today that said "When it comes to worship, do you think of Charles Wesley before Chris Tomlin, is worship music more pipe organ than iPod to you?" Which started me thinking about timeless hymns of old like "How great thou art" and "Great is thy faithfulness". I know that that ad was directed at older people who would prefer the older songs to the newer stuff, but how do I feel about hymns and modern worship music?
 
First let me say that my parents took me to church since I was born and in that church we would sing an even combination of old hymns from the baptist hymnal and a selection of songs from the late 20th century, particularly the eighties from a number of sources such as Hillsong Australia (in the form of Geoff Bullock) and Vinyard. As a teenager I became very dissatisfied with this music in the light of my secular music tastes, experiences with a local youth group and churches I visited from time to time, and Christian music CDs I purchased from a local Christian bookstore. When I eventually left that church and joined the aforementioned youth group for other deeper and more positive reasons, I was also glad that I had left those songs behind me.
 
Nowadays, however I feel somewhat disappointed with the songs that I loved a few years ago and uninterested in the popular Christian worship songs being produced today. I feel a special connection with the timeless hymns of old who’s lyrical and musical genius are insignificant compared the the anointing that God has placed upon them. In a few years the world will forget "How great is our God" and "Here I am to worship" but I doubt we’ll ever forget "Amazing Grace" or "How great thou art". Something about these songs helps them to endure the tides of popular music as if unlike all other music they simply do not depend in any way on the musical taste of the culture or the listener.
 
So am I saying that modern worship songs are a waste of breath? Or that if you like them better than my favorite hymns you’re a bad Christian? of course not. God’s word is living and active, and part of that truth involves the writing of new songs. God is always speaking to His people and songs are a great way to cut past the intellectual barriers we put up. If Churches today sung only the old hymns then think of the many thousands of men and women who would not respond to the Gospel message and the many more who, though saved would struggle to connect with God. I am glad to live in an age where Christian music is being produced that helps ordinary people like me connect with God on an intimate level. On top of this, new songs often reveal something to me I hadn’t considered or help me believe in my heart something I already agree with in my mind.
 
Just don’t ever throw out my favorite hymns.
 

Writer’s Block: The Meaning of Love

What does love mean to me? Love is a not a feeling in my understanding, love is not warm fuzzies. Love is a verb, love is an action. Helping someone to use their computer – that’s loving someone. Love is self-sacrifice, love is losing out so others can win. Love is being patient with someone, love is being kind to someone. Love can’t be envious of another and it can’t be arrogant either – that’s just not love. Most importantly to me, love doesn’t keep a list of mistakes – no it forgets these things, they are done and gone.
If you love someone, you won’t lie to them, no matter how bad the truth makes you look – love tells the truth.
Love is believing in someone even though they seem to you like a failure now, and love doesn’t give up, it keeps on believing.

Computer Games

So I’m out of a job and uni is on break for the summer. What should I do with my time? I have endless bounds of time to do all the things that I used to love doing… now what were they? That’s right – games and dvds, the stuff that everyone else seems to love doing that I’ve never had time for because I’ve been working and studying.

After a month out of work and uni, I’ve realised that I should have left games and watching movies in the past, I’ve grown out of that now – I’m 22. My friends bought me half-life 2, counterstrike source and World of Warcraft for my birthday/christmas present this year, and whilst I was extremely thankful for the gifts, I quickly realised that a pack of cigarettes and some beer would have done less damage to my lifestyle and my relationship with God.

Firstly, I take offence to the amount of fantasy, mysticism, magic and downright evil content in the game world of warcraft, but I chose to live with it to be part of the scene. Quickly I became addicted to the point where I would spend up to 5 hours a day playing this ridiculous game, it was slowly, but surely sucking my life away. This morning I uninstalled World of Warcraft and Half life 2 in a bid to get my life back. The real world was moving all around me but all I cared about was that game, and now I’ve got sooo much catching up to do, did you know that it’s december? I barely acknowledged it.

With watching movies, I’ve realised that watching them does nothing for me, just fills my head with images which in a lot of cases i shouldnt be filling it with. I want to spend time with friends where I actually get to know them better and share life with them, rather than watching movies.

So, I’m kind of in a no man’s land right now, I really want to watch star trek: voyager, but I know that there’s no point in watching it again, and I am just looking for comfort activities, things that used to make me happy in high school, where I should be spending time with God, reading books and actually earning a living.

Sigh. Guess I’d better do some work today.

Self Discovery

A few weeks ago, ade gave me a photocopy of a section of a book called
‘Esssential habits of an affective teenager’ (or something like that).
In it it asks me to answer several far out and personal questions. So
here are my answers:

1. Think of a person who has made a
positive difference in your life. What qualities does that person have
that you would like to develop?

Adrian Wauchope:
Adrian is my mentor and my big brother in Christ. He has helped me to
mature as a Christian man and release some of my potential. Adrian is
outgoing and friendly, he is never shy and eager to give handshakes and
or hugs. Adrian is all about encouragement and wants to help younger
men to develop thier Christian walk. Adrian would never leave a man
behind, no matter how unpopular.
Michael Crocombe:
Michael is my boss and has been for a few years. I am like an
apprentice to him, learning business and life skills. Michael is wise
and discerning, never quick to anger and never rushes in. Michael will
put all of himself into something he believes in.

2. Imagine 20 years from now you are surrounded by the most important people in your life. Who are they and what are you doing?
I am in a dissused factory in the heart of bombay directing a team of
skilled workers to install Information Technology and production
equipment for an upcoming major evangelistic event, At my side is a
young man in his late 20s – my apprentice – he is learning the finer
points of managing IT and production as he will take my place when I
retire. At lunch I am joined by my pastor, a german evangelist with a
heart for India. He depends on me to provide the technological support
for his ministry. I am also joined by my wife of eleven years and my
nine year old daughter Kathrine. She is practicing playing the flute,
which she is learning to supplement her existing vocal and piano
talents. She has only a healthy interest in technology and has plenty
of friends at school.

3. If a steel beam (6 inches wide)
were placed across two skyscrapers, for what would you be willing to
cross? A thousand dollars? A million? Your pet? Your brother? Fame?
Think carefully….

a) If that action were necessary to bring about the salvation of my friend Nathan or someone I am friends with in the future.
b) To prove that I am a worthy husband to my wife to be or to her parents
c) To save any of my children form any serious harm



4. If you could spend a day in a great library studying anything you wanted, what would you study?
The early church: 1ad-200ad

5. List ten things you love to do:
(not in any order)
  1. Worship God
  2. Write software
  3. Run production
  4. Hack (install difficult software, make changes to existing software)
  5. Listen to music
  6. Play music
  7. Learn to do something new
  8. Create visual art
  9. Write
  10. Serve God

6. Describe a time when you were deeply inspired
I was once inspired when I went into the bush and talked to God and
took photos of his beautiful creation. I was inspired by the grandure
and intracacy of His creation.

7. Five years from now, your local
paper does a story about you and they want to interview three people…
a parent and two friends. What would you want them to say about you?

I would want them to say that I really care about people, always do
what is right and fight against injustice. I want them to say that
Jesus is always first in my life. I want them to say that I built my
house upon the rock and cannot not be moved.

8. Think of something that represents you… a rose, a song, an animal… why does it represent you?
I am a lighthouse built upon the Rock. With Jesus as my firm foundation
I will weather the storm. With the light of the world inside me, I will
shine his light in the world, even in the darkest night. I will not be
moved.

9. If you could spend an hour with any person who ever lived, who would that person be? Why that person? What would you ask?
It would have to be Jesus disciple; Peter. Though he stumbled  and
fell, he gave his all for Jesus, and God made him a solid rock to build
his church upon.

10. Everyone has one or more talents, what are you good at?
Technology
Production
Music
Visual Art
Writing

What kind of conclusion can I draw from all that? I havn’t a clue.A few weeks ago, ade gave me a photocopy of a section of a book called ‘Esssential habits of an affective teenager’ (or something like that). In it it asks me to answer several far out and personal questions. So here are my answers:

1. Think of a person who has made a positive difference in your life. What qualities does that person have that you would like to develop?
Adrian Wauchope:
Adrian is my mentor and my big brother in Christ. He has helped me to mature as a Christian man and release some of my potential. Adrian is outgoing and friendly, he is never shy and eager to give handshakes and or hugs. Adrian is all about encouragement and wants to help younger men to develop thier Christian walk. Adrian would never leave a man behind, no matter how unpopular.
Michael Crocombe:
Michael is my boss and has been for a few years. I am like an apprentice to him, learning business and life skills. Michael is wise and discerning, never quick to anger and never rushes in. Michael will put all of himself into something he believes in.

2. Imagine 20 years from now you are surrounded by the most important people in your life. Who are they and what are you doing?
I am in a dissused factory in the heart of bombay directing a team of skilled workers to install Information Technology and production equipment for an upcoming major evangelistic event, At my side is a young man in his late 20s – my apprentice – he is learning the finer points of managing IT and production as he will take my place when I retire. At lunch I am joined by my pastor, a german evangelist with a heart for India. He depends on me to provide the technological support for his ministry. I am also joined by my wife of eleven years and my nine year old daughter Kathrine. She is practicing playing the flute, which she is learning to supplement her existing vocal and piano talents. She has only a healthy interest in technology and has plenty of friends at school.

3. If a steel beam (6 inches wide) were placed across two skyscrapers, for what would you be willing to cross? A thousand dollars? A million? Your pet? Your brother? Fame? Think carefully….

a) If that action were necessary to bring about the salvation of my friend Nathan or someone I am friends with in the future.
b) To prove that I am a worthy husband to my wife to be or to her parents
c) To save any of my children form any serious harm

4. If you could spend a day in a great library studying anything you wanted, what would you study?
The early church: 1ad-200ad

5. List ten things you love to do:
(not in any order)
1. Worship God
2. Write software
3. Run production
4. Hack (install difficult software, make changes to existing software)
5. Listen to music
6. Play music
7. Learn to do something new
8. Create visual art
9. Write
10. Serve God

6. Describe a time when you were deeply inspired
I was once inspired when I went into the bush and talked to God and took photos of his beautiful creation. I was inspired by the grandure and intracacy of His creation.

7. Five years from now, your local paper does a story about you and they want to interview three people… a parent and two friends. What would you want them to say about you?
I would want them to say that I really care about people, always do what is right and fight against injustice. I want them to say that Jesus is always first in my life. I want them to say that I built my house upon the rock and cannot not be moved.

8. Think of something that represents you… a rose, a song, an animal… why does it represent you?
I am a lighthouse built upon the Rock. With Jesus as my firm foundation I will weather the storm. With the light of the world inside me, I will shine his light in the world, even in the darkest night. I will not be moved.

9. If you could spend an hour with any person who ever lived, who would that person be? Why that person? What would you ask?
It would have to be Jesus disciple; Peter. Though he stumbled and fell, he gave his all for Jesus, and God made him a solid rock to build his church upon.

10. Everyone has one or more talents, what are you good at?
Technology
Production
Music
Visual Art
Writing

What kind of conclusion can I draw from all that? I havn’t a clue.

2GO Forrest Classic rally

Yesterday I went to the scrutineering session for a local rally through ourimbah state forest to test out a software package that I’ve been writing for that purpose. For those who don’t know. Scrutineering is like a rego check, only a little more strict and thourough. Our program is designed to manage the registration of persons into events and the generation of scrutineering reports and other documentation upon the checks taking place. Our system was intended to be run side-by-side with the existing paper system, since it is not exactly stable at this point, unfortunately the old system failed miserably, so the scrutineering depended upon our program working propery. Thankfully it did.

We printed pass certificates on the spot, and reports back down to the admin room over a wifi link, in fact everything was running on a wifi link, it was great. Once again I got a job offer from some guy looking for young web-savvy guys to work for him. Not sure If I’ll take up his offer, since I already have a good job and I’m overworked….

Also, speaking of overworked: I was not feeling too great on thursday night but instead of taking it easy, i was up until 1am the next morning programming, then I got to the scrutineering at about 9:00am and left at 9:15pm, so I was almost dead when I got home, and Was rather sick last night. Must rest….