/
login_ecdsa.go
107 lines (101 loc) · 2.96 KB
/
login_ecdsa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2016 The go-daylight Authors
// This file is part of the go-daylight library.
//
// The go-daylight library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-daylight library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-daylight library. If not, see <http://www.gnu.org/licenses/>.
package controllers
import (
"github.com/EGaaS/go-egaas-mvp/packages/utils"
"io/ioutil"
"path/filepath"
"strconv"
"strings"
)
type loginECDSAPage struct {
Lang map[string]string
Title string
Key string
// States map[string]string
States string
State int64
OneCountry int64
PrivCountry bool
Import bool
Local bool
Private string
}
// LoginECDSA is a control for the login page
func (c *Controller) LoginECDSA() (string, error) {
var err error
var private []byte
local := strings.HasPrefix(c.r.Host, `localhost`)
if c.ConfigIni["public_node"] != "1" || local {
private, _ = ioutil.ReadFile(filepath.Join(*utils.Dir, `PrivateKey`))
}
/* states := make(map[string]string)
data, err := c.GetList(`SELECT id FROM system_states`).String()
if err != nil {
return ``, err
}
for _, id := range data {
state_name, err := c.Single(`SELECT value FROM "` + id + `_state_parameters" WHERE name = 'state_name'`).String()
if err != nil {
return ``, err
}
states[id] = state_name
}*/
states, _ := c.AjaxStatesList()
key := c.r.FormValue("key")
pkey := c.r.FormValue("pkey")
state := c.r.FormValue("state")
if len(key) > 0 || len(pkey) > 0 {
c.Logout()
}
if len(pkey) > 0 {
private = []byte(pkey)
}
var stateID int64
if len(state) > 0 {
stateID, err = strconv.ParseInt(state, 10, 64)
if err != nil {
list, err := utils.DB.GetAllTables()
if err != nil {
return "", utils.ErrInfo(err)
}
if utils.InSliceString(`global_states_list`, list) {
stateID, err = c.Single("select gstate_id from global_states_list where state_name=?", state).Int64()
if err != nil {
return "", utils.ErrInfo(err)
}
}
}
}
TemplateStr, err := makeTemplate("login", "loginECDSA", &loginECDSAPage{
Lang: c.Lang,
Title: "Login",
States: states,
State: stateID,
Key: key,
Local: local,
Import: len(pkey) > 0,
OneCountry: utils.OneCountry,
PrivCountry: utils.PrivCountry,
Private: string(private),
/* MyWalletData: MyWalletData,
Title: "modalAnonym",
*/})
if err != nil {
return "", utils.ErrInfo(err)
}
return TemplateStr, nil
}