<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>{{title}} - {{ _("BTSBots wallet") }}</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin-2.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!-- jQuery -->
    <script src="js/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="js/metisMenu.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="js/sb-admin-2.js"></script>

    <script type="text/javascript" charset="utf-8">
        $(document).ready(function(){
                action = {{ action|tojson|safe }}
                if (action == "logout"){
                document.cookie="address="
                }
                //console.log(JSON.stringify(msg))
                if (localStorage.account) {
                account_list = JSON.parse(localStorage.account)
                for (index in account_list){
                account = account_list[index]["account"]
                address = account_list[index]["address"]
                if(account==""){
                 account= address
                }
                document.getElementById("account_list").innerHTML += "<option>"+account+"</option>"
                }
                }
                document.getElementById("account_list").innerHTML += "<option>demo.btsbots</option>"
        });
    </script>
    <script src=js/bitshares.min.js></script>
    <script type="text/javascript" charset="utf-8">
           login = function () {
               account = document.getElementById("account_list").value
               document.cookie="account="+account
                   if (account == "demo.btsbots") {
                           document.cookie="address=BTS4JLfbQNkDi7WB3QNVkzT2RdmXPemBus4G"
                           sessionStorage.key_hex="791fb064d4c9154b8c8c1a5068a6faa7664943f05fb325bf2d2ef6e80f2ce39a";
                           return true
                   }
                   for (index in account_list){
                    if (account_list[index]["account"] == account ||
                    account_list[index]["address"] == account){
                         key_enc = account_list[index]["key"]
                         break
                    }
                }
                   try {
                       secret = document.getElementById("password").value
                           aes = bts.ecc.Aes.fromSecret(secret)
                           key_hex = aes.decryptHex(key_enc)
                           key = bts.ecc.PrivateKey.fromHex(key_hex)
                           address = key.toPublicKey().toBtsAddy()
                           document.cookie="address="+address
                           sessionStorage.key_hex=key_hex;
                   }
               catch(err)
               {
                   console.log(err)
                       document.getElementById("msg").innerHTML="{{ _('wrong password') }}"
                   return false
               }
           }
    </script>

</head>

<body>

    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div class="login-panel panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title">{{ _("Sign in") }}<small class="pull-right">or <a href="new">{{ _("Add account") }}</a></small></h3>
                    </div>
                    <div class="panel-body">
                                <div class="form-group">
                                    <label>{{ _("Select Account") }}</label>
                                            <select id="account_list" class="form-control">
                                            </select>
                                </div>
                                <div class="form-group">
                                    <input class="form-control" id="password" placeholder="Decrypt Password" type="password" value="">
                                    <label id="msg"></label>
                                </div>
                        <form role="form" action="/" onsubmit="return login()">
                            <fieldset>
                                <!-- Change this to a button or input when using this as a form -->
                                <input type="SUBMIT" value="{{ _("Login") }}" class="btn btn-lg btn-success btn-block">
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>

</html>

