From 617434c79375471fb441c332dea82a9074a7f8df Mon Sep 17 00:00:00 2001 From: Alexey Krivonogov Date: Wed, 25 May 2016 10:52:03 +0500 Subject: [PATCH 01/19] Added patterns for dcoin notifications --- packages/emailserv/balance.go | 119 +++++++++++------------ packages/emailserv/common.go | 117 +++++++++++++++++++++++ packages/emailserv/daemon.go | 18 ++-- packages/emailserv/emailserv.go | 161 ++++++++++++++------------------ 4 files changed, 251 insertions(+), 164 deletions(-) create mode 100644 packages/emailserv/common.go diff --git a/packages/emailserv/balance.go b/packages/emailserv/balance.go index b1345d9..7988380 100644 --- a/packages/emailserv/balance.go +++ b/packages/emailserv/balance.go @@ -5,10 +5,9 @@ import ( "net/http" "github.com/democratic-coin/dcoin-go/packages/utils" "github.com/democratic-coin/dcoin-go/packages/controllers" + "encoding/json" // "html/template" "bytes" - "hash/crc32" - "strconv" // "io" "fmt" "strings" @@ -42,15 +41,6 @@ func balanceDaemon() { func BalanceProceed() { bMutex.Lock() task := queueBalance[ bCurrent ] - subject := new(bytes.Buffer) - html := new(bytes.Buffer) - text := new(bytes.Buffer) - pattern := `balance` -// text := new(bytes.Buffer) - - if err := GPagePattern.ExecuteTemplate(subject, pattern + `Subject`, nil ); err != nil { - task.Error = err - } // Защита от повторной рассылки for i:=0; i 0 || len(text.String()) > 0 { - if task.Error == nil { - bcc := GSettings.CopyTo - GSettings.CopyTo = `` - - if data[`List`].(map[int64]*infoBalance)[72] != nil && data[`List`].(map[int64]*infoBalance)[72].Tdc > 100 { - task.Error = fmt.Errorf(`Too much Tdc=%f`, data[`List`].(map[int64]*infoBalance)[72].Tdc ) - } else if err := GEmail.SendEmail( html.String(), text.String(), subject.String(), - []*Email{&Email{``, user[`email`] }}); err != nil { - GDB.ExecSql(`update users set verified = -1 where user_id=?`, task.UserId ) - task.Error = err - } else { - // log.Println( `Balance Sent:`, user[`email`], userId ) - GDB.ExecSql(`INSERT INTO log ( user_id, email, cmd, params, uptime, ip ) - VALUES ( ?, ?, ?, ?, datetime('now'), ? )`, - task.UserId, user[`email`], utils.ECMD_BALANCE, ``, 1 ) - icur := int64(72) - if data[`List`].(map[int64]*infoBalance)[icur] == nil || data[`List`].(map[int64]*infoBalance)[icur].Tdc == 0 { - for icur := range data[`List`].(map[int64]*infoBalance) { - if icur != 1 { - break - } - } - } - if data[`List`].(map[int64]*infoBalance)[icur] != nil { - task.Error = fmt.Errorf(`Sent Currency=%d Wallet=%f Tdc=%f Promised=%f`, icur, - data[`List`].(map[int64]*infoBalance)[icur].Wallet, - data[`List`].(map[int64]*infoBalance)[icur].Tdc, - data[`List`].(map[int64]*infoBalance)[icur].Promised ) +// data[`nobcc`] = true + + if data[`List`].(map[int64]*infoBalance)[72] != nil && data[`List`].(map[int64]*infoBalance)[72].Summary > 100 { + task.Error = fmt.Errorf(`Too much Summary=%f`, data[`List`].(map[int64]*infoBalance)[72].Summary ) + } else if EmailUser( task.UserId, data, utils.ECMD_BALANCE ) { + icur := int64(72) + if data[`List`].(map[int64]*infoBalance)[icur] == nil || data[`List`].(map[int64]*infoBalance)[icur].Tdc == 0 { + for icur := range data[`List`].(map[int64]*infoBalance) { + if icur != 1 { + break } } - GSettings.CopyTo = bcc + } + if data[`List`].(map[int64]*infoBalance)[icur] != nil { + task.Error = fmt.Errorf(`Sent Currency=%d Wallet=%f Tdc=%f Promised=%f`, icur, + data[`List`].(map[int64]*infoBalance)[icur].Wallet, + data[`List`].(map[int64]*infoBalance)[icur].Tdc, + data[`List`].(map[int64]*infoBalance)[icur].Promised ) } } else { - task.Error = fmt.Errorf(`Wrong HTML and Text patterns`) + task.Error = fmt.Errorf(`Error sending`) } } bCurrent++ @@ -131,8 +93,10 @@ type infoBalance struct { CurrencyId int64 Wallet float64 Tdc float64 + Summary float64 Promised float64 Restricted float64 + Top float64 } func getBalance( userId int64, data *map[string]interface{} ) error { @@ -141,7 +105,7 @@ func getBalance( userId int64, data *map[string]interface{} ) error { if wallet, err := utils.DB.GetBalances(userId); err == nil { for _, iwallet := range wallet { list[iwallet.CurrencyId] = &infoBalance{ CurrencyId: iwallet.CurrencyId, - Wallet: iwallet.Amount } + Wallet: utils.Round(iwallet.Amount, 6) } } } else { return err @@ -150,11 +114,11 @@ func getBalance( userId int64, data *map[string]interface{} ) error { if _, dc, _, err := utils.DB.GetPromisedAmounts( userId, vars.Int64["cash_request_time"]); err == nil { for _, idc := range dc { if _, ok:= list[idc.CurrencyId]; ok { - list[idc.CurrencyId].Tdc = idc.Tdc - list[idc.CurrencyId].Promised = idc.Amount + list[idc.CurrencyId].Tdc += utils.Round(idc.Tdc,6) + list[idc.CurrencyId].Promised += idc.Amount } else { list[idc.CurrencyId] = &infoBalance{ CurrencyId: idc.CurrencyId, - Promised: idc.Amount, Tdc: idc.Tdc } + Promised: idc.Amount, Tdc: utils.Round(idc.Tdc, 6) } } } } else { @@ -173,15 +137,33 @@ func getBalance( userId int64, data *map[string]interface{} ) error { if profit,_, err := c.GetPromisedAmountCounter(); err == nil && profit > 0 { currency := int64(72) if _, ok:= list[currency]; ok { - list[currency].Restricted = profit - 30 + list[currency].Restricted = utils.Round( profit - 30, 6) } else { list[currency] = &infoBalance{ CurrencyId: currency, - Restricted: profit - 30 } + Restricted: utils.Round( profit - 30, 6) } } } - + forjson := make( map[string]float64 ) for i := range list { list[i].Currency,_ = utils.DB.Single(`select name from currency where id=?`, list[i].CurrencyId ).String() + list[i].Summary = utils.Round( list[i].Wallet + list[i].Tdc + list[i].Restricted, 6 ) + forjson[ utils.Int64ToStr(list[i].CurrencyId) ] = list[i].Summary + off := float64(10) + for k:=0; k<5; k++ { + if list[i].Summary < off { + list[i].Top = utils.Round( list[i].Summary, 4 - k ) + break + } + off *= 10 + } + if list[i].Top == 0 { + list[i].Top = utils.Round( list[i].Summary, 0 ) + } + } + out,_ := json.Marshal( forjson ) + if len(out) > 0 { + GDB.ExecSql(`insert into balance ( user_id, balance, uptime) values( ?, ?, datetime('now'))`, + userId, out ) } (*data)[`List`] = list return nil @@ -215,7 +197,10 @@ func balanceHandler(w http.ResponseWriter, r *http.Request) { } bMutex.Lock() for _, iduser := range users { - queueBalance = append( queueBalance, &balanceTask{ UserId: utils.StrToInt64( iduser ) }) + userId := utils.StrToInt64( iduser ) + if !utils.InSliceInt64(userId, []int64{ 30, 158, 879, 705, 385, 490, 111 }) { + queueBalance = append( queueBalance, &balanceTask{ UserId: userId }) + } } bMutex.Unlock() http.Redirect(w, r, `/` + GSettings.Admin + `/balance`, http.StatusFound ) diff --git a/packages/emailserv/common.go b/packages/emailserv/common.go new file mode 100644 index 0000000..c1c4751 --- /dev/null +++ b/packages/emailserv/common.go @@ -0,0 +1,117 @@ +// common +package main + +import ( + "github.com/democratic-coin/dcoin-go/packages/utils" + "fmt" + "log" + "bytes" + "hash/crc32" + "strconv" + "html/template" +) + +func CheckUser( userId int64 ) (map[string]interface{}, error) { + + user, err := GDB.OneRow("select * from users where user_id=?", userId ).String() + if err != nil { + return nil, err + } + if len(user) == 0 { + return nil, fmt.Errorf(`The user has no email`) + } else if utils.StrToInt( user[`verified`] ) < 0 { + return nil, fmt.Errorf(`The user in the stop-list`) + } + data := make(map[string]interface{}) + data[`email`] = user[`email`] + data[`Unsubscribe`] = fmt.Sprintf( `%s/unsubscribe?uid=%d-%s`, + utils.EMAIL_SERVER, userId, strconv.FormatUint( uint64( crc32.ChecksumIEEE([]byte(user[`email`]))), 32 )) + + lang := utils.StrToInt64( user[`lang`] ) + if lang == 0 { + if country, err := utils.DB.Single(`select country from miners_data where user_id=?`, userId ).Int64(); err == nil { + switch country { + case 10, 14, 19, 67, 80, 112, 119, 125, 180, 214, 224, 230, 235: + lang = 42 + } + } else { + lang = 1 + } + if err := GDB.ExecSql(`update users set lang=? where user_id=?`, lang, userId ); err != nil { + return nil, err + } + } + data[`lang`] = lang + return data, nil +} + +func EmailUser( userId int64, data map[string]interface{}, cmd int ) bool { + + result := func( msg string ) bool { + log.Println( fmt.Sprintf( `Error: user_id=%d %s`, userId, msg )) + return false + } + + patterns := []string{ `unknown`, `new`, `test`, `adminmsg`, `cashreq`, `changestat`, + `dccame`, `dcsent`, `updprimary`,`updemail`, `updsms`, `voteres`, + `votetime`, `newver`, `nodetime`, `signup`, `balance`} + pattern := patterns[cmd] + if len(pattern) == 0 { + pattern = data[`pattern`].(string) + } + + subject := new(bytes.Buffer) + html := new(bytes.Buffer) + lang := utils.Int64ToStr( data[`lang`].(int64) ) + if data[`lang`].(int64) > 1 { + GPagePattern.ExecuteTemplate(subject, pattern + `Subject` + lang, data ) + GPagePattern.ExecuteTemplate(html, pattern + `HTML` + lang, data ) + } + if len( subject.String()) == 0 { + GPagePattern.ExecuteTemplate(subject, pattern + `Subject`, data ) + } + if len( html.String()) == 0 { + GPagePattern.ExecuteTemplate(html, pattern + `HTML`, data ) + } + if len( html.String()) == 0 { + return result( `Empty pattern ` + pattern ) + } + data[`Body`] = template.HTML(html.String()) + html.Reset() + if data[`lang`].(int64) > 1 { + if len( subject.String()) == 0 { + GPagePattern.ExecuteTemplate(subject, `commonSubject` + lang, data ) + } + GPagePattern.ExecuteTemplate(html, `commonHTML` + lang, data ) + } + if len( subject.String()) == 0 { + GPagePattern.ExecuteTemplate(subject, `commonSubject`, data ) + } + if len( html.String()) == 0 { + GPagePattern.ExecuteTemplate(html, `commonHTML`, data ) + } + if len( subject.String()) == 0 { + subject.WriteString(`DCoin notifications`) + } + bcc := GSettings.CopyTo + if _, ok := data[`nobcc`]; ok { + GSettings.CopyTo = `` + } + err := GEmail.SendEmail( html.String(), ``, subject.String(), + []*Email{&Email{``, data[`email`].(string) }}) + if _, ok := data[`nobcc`]; ok { + GSettings.CopyTo = bcc + } + if err != nil { + GDB.ExecSql(`UPDATE users SET verified=? WHERE user_id=?`, -1, userId ) + return result( fmt.Sprintf(`SendPulse %s`, err.Error())) + } + + log.Println( `Daemon Sent:`, cmd, data[`email`].(string), userId ) + if err := GDB.ExecSql(`INSERT INTO log ( user_id, email, cmd, params, uptime, ip ) + VALUES ( ?, ?, ?, ?, datetime('now'), ? )`, + userId, data[`email`].(string), cmd, ``, 1 ); err != nil { + return result( err.Error() ) + } + return true +} diff --git a/packages/emailserv/daemon.go b/packages/emailserv/daemon.go index 2d7e2e5..145920a 100644 --- a/packages/emailserv/daemon.go +++ b/packages/emailserv/daemon.go @@ -2,15 +2,11 @@ package main import ( - "fmt" "github.com/democratic-coin/dcoin-go/packages/utils" "log" - "bytes" - "strconv" - "hash/crc32" ) -func sendEmail( pattern string, cmd int, userId int64, data *map[string]interface{} ) bool { +/*func sendEmail( pattern string, cmd int, userId int64, data *map[string]interface{} ) bool { result := func( msg string ) bool { log.Println( fmt.Sprintf( `Daemon Error: user_id=%d %s`, userId, msg )) @@ -72,7 +68,7 @@ func sendEmail( pattern string, cmd int, userId int64, data *map[string]interfac return result( err.Error() ) } return true -} +}*/ func daemon() { latest := make(map[int]int64) @@ -95,8 +91,14 @@ func daemon() { if err = GDB.ExecSql(`UPDATE latest SET latest=? WHERE cmd_id=?`, last, utils.ECMD_CASHREQ ); err!=nil { log.Println( err ) } - sendEmail( `cashreq`, utils.ECMD_CASHREQ, utils.StrToInt64( cash[`to_user_id`] ), - &map[string]interface{}{ `Amount`: cash[`amount`], `Currency`: cash[`currency`], `FromUserId`: cash[`from_user_id`] }) + userId := utils.StrToInt64( cash[`to_user_id`] ) + data, err := CheckUser( userId ) + if err == nil { + data[`Amount`] = cash[`amount`] + data[`Currency`] = cash[`currency`] + data[`FromUserId`] = cash[`from_user_id`] + EmailUser( userId, data, utils.ECMD_CASHREQ ) + } latest[utils.ECMD_CASHREQ] = last } utils.Sleep( 10 ) diff --git a/packages/emailserv/emailserv.go b/packages/emailserv/emailserv.go index eca249c..3189116 100644 --- a/packages/emailserv/emailserv.go +++ b/packages/emailserv/emailserv.go @@ -19,8 +19,6 @@ import ( "os" "path/filepath" "html/template" - "hash/crc32" - "strconv" // "regexp" // "net/url" "strings" @@ -210,34 +208,38 @@ func emailHandler(w http.ResponseWriter, r *http.Request) { result(err.Error()) return }*/ - var ( +/* var ( params []byte - text, subject string - ) + )*/ if jsonEmail.Params == nil { jsonEmail.Params = &map[string]string{} } - if len(*jsonEmail.Params) > 0 { +/* if len(*jsonEmail.Params) > 0 { params, _ = json.Marshal(jsonEmail.Params) - } - subject = `DCoin notifications` + }*/ switch jsonEmail.Cmd { - case utils.ECMD_NEW, utils.ECMD_TEST: - text = `Test` - subject = `Test` + case utils.ECMD_NEW, utils.ECMD_TEST, utils.ECMD_SIGNUP, utils.ECMD_UPDPRIMARY, utils.ECMD_VOTETIME: + case utils.ECMD_UPDEMAIL: + if err := checkParams(`email`); err != nil { + result(err.Error()) + return + } case utils.ECMD_ADMINMSG: if err := checkParams(`msg`); err != nil { result(err.Error()) return } - text = `From Admin: ` + (*jsonEmail.Params)[`msg`] -/* case utils.ECMD_CASHREQ: - if err := checkParams(`amount`, `currency`); err != nil { + case utils.ECMD_VOTERES: + if err := checkParams(`text`); err != nil { + result(err.Error()) + return + } + case utils.ECMD_UPDSMS: + if err := checkParams(`sms`); err != nil { result(err.Error()) return } - text = fmt.Sprintf(`You"ve got the request for %s %s. It has to be repaid within the next 48 hours.`, - (*jsonEmail.Params)[`amount`], (*jsonEmail.Params)[`currency`])*/ + (*jsonEmail.Params)[`sms`] = `New sms_http_get_request ` + (*jsonEmail.Params)[`sms`] /* case utils.ECMD_CHANGESTAT: if err := checkParams(`status`); err != nil { result(err.Error()) @@ -249,50 +251,16 @@ func emailHandler(w http.ResponseWriter, r *http.Request) { result(err.Error()) return } - text = fmt.Sprintf(`You've got %s D%s %s`, (*jsonEmail.Params)[`amount`], - (*jsonEmail.Params)[`currency`], (*jsonEmail.Params)[`comment`]) case utils.ECMD_DCSENT: if err := checkParams(`amount`, `currency`); err != nil { result(err.Error()) return } - text = fmt.Sprintf(`Debiting %s D%s`, (*jsonEmail.Params)[`amount`], (*jsonEmail.Params)[`currency`]) - case utils.ECMD_UPDPRIMARY: - text = `Update primary key` - case utils.ECMD_UPDEMAIL: - if err := checkParams(`email`); err != nil { - result(err.Error()) - return - } - text = `New email: ` + (*jsonEmail.Params)[`email`] - case utils.ECMD_UPDSMS: - if err := checkParams(`sms`); err != nil { - result(err.Error()) - return - } - text = `New sms_http_get_request ` + (*jsonEmail.Params)[`sms`] - case utils.ECMD_VOTERES: - if err := checkParams(`text`); err != nil { - result(err.Error()) - return - } - text = (*jsonEmail.Params)[`text`] - case utils.ECMD_VOTETIME: - text = `It's 2 weeks from the moment you voted.` - case utils.ECMD_NEWVER: - if err := checkParams(`version`); err != nil { - result(err.Error()) - return - } - text = `New version: ` + (*jsonEmail.Params)[`version`] case utils.ECMD_NODETIME: if err := checkParams(`dif`); err != nil { result(err.Error()) return } - text = fmt.Sprintf("Divergence time %s sec", (*jsonEmail.Params)[`dif`]) - case utils.ECMD_SIGNUP: - text = `` default: result(fmt.Sprintf(`Unknown command %d`, jsonEmail.Cmd)) return @@ -302,39 +270,39 @@ func emailHandler(w http.ResponseWriter, r *http.Request) { result(fmt.Sprintf(`Email %s is in the stop-list`, jsonEmail.Email)) return } - - if len(text) > 0 { - footer := fmt.Sprintf( `

Service of Dcoin notifications

Unsubscribe Dcoin notifications

`, - utils.EMAIL_SERVER, jsonEmail.UserId, strconv.FormatUint( uint64( crc32.ChecksumIEEE([]byte(jsonEmail.Email))), 32 )) - if err = GEmail.SendEmail("

"+text+"

" + footer, ``, subject, - []*Email{&Email{``, jsonEmail.Email}}); err != nil { - errsend := fmt.Sprintf(`SendPulse %s`, err.Error()) - GDB.ExecSql(`INSERT INTO stoplist ( email, error, uptime, ip ) - VALUES ( ?, ?, datetime('now'), ? )`, - jsonEmail.Email, errsend, ipval) - result(errsend) - return - } - } if (jsonEmail.Cmd == utils.ECMD_NEW || jsonEmail.Cmd == utils.ECMD_SIGNUP ) && len(email)==0 { if err = GDB.ExecSql(`INSERT INTO users (user_id, email, newemail, verified, code, lang ) VALUES(?,?,'', 0, 0, 0)`, jsonEmail.UserId, jsonEmail.Email ); err!=nil { log.Println(remoteAddr, `Error new user:`, err, jsonEmail.Email) } } - GDB.ExecSql(`INSERT INTO log ( user_id, email, cmd, params, uptime, ip ) - VALUES ( ?, ?, ?, ?, datetime('now'), ? )`, - jsonEmail.UserId, jsonEmail.Email, jsonEmail.Cmd, string(params), ipval) - /* if err != nil { - result( fmt.Sprintf(`SQL error %v`, err)) - return - }*/ + + if jsonEmail.Cmd != utils.ECMD_SIGNUP { + data, err := CheckUser( jsonEmail.UserId ) + if err != nil { + result( fmt.Sprintf(`EmailCheck %s`, err)) + return + } + for key, value := range *jsonEmail.Params { + data[strings.ToUpper(key[:1]) + key[1:]] = value + } + if _,ok := data[`Msg`]; ok { + data[`Msg`] = template.HTML(data[`Msg`].(string)) + } + if _,ok := data[`Text`]; ok { + data[`Text`] = template.HTML(data[`Text`].(string)) + } + if !EmailUser( jsonEmail.UserId, data, int(jsonEmail.Cmd) ) { + result( `EmailUser`) + return + } + } answer.Success = true result(``) } - -/*func Send() { +/* +func Send() { time.Sleep( 5 * time.Second ) Client := &http.Client{ @@ -370,20 +338,21 @@ func emailHandler(w http.ResponseWriter, r *http.Request) { func Send() { time.Sleep(5 * time.Second) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_TEST, nil /*&map[string]string{})) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_ADMINMSG, &map[string]string{`msg`: `

Header

`})) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_CASHREQ, &map[string]string{`amount`: `

Header

`, `currency`: `USD`})) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_CHANGESTAT, &map[string]string{`status`: `miner`})) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_DCCAME, &map[string]string{ `amount`: `10`, -// `currency`: `USD`, `comment`: `

Header

` })) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_DCSENT, &map[string]string{`amount`: `111`, `currency`: `USD`})) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_UPDPRIMARY, nil )) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_UPDEMAIL, &map[string]string{ `email`: `my@newemail.com` })) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_UPDSMS, &map[string]string{ `sms`: `my SMS` })) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_VOTERES, &map[string]string{ `text`: `Voting result` })) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_VOTETIME, nil )) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_NEWVER, &map[string]string{ `version`: `2.1.3` } )) -// fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_NODETIME, &map[string]string{ `dif`: `7` } )) + emailhere := `` + var userId int64 = 0 + fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_TEST, nil )) + fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_ADMINMSG, &map[string]string{`msg`: `

Header

`})) + fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_CASHREQ, &map[string]string{`amount`: `

Header

`, `currency`: `USD`})) + fmt.Println("Result", utils.SendEmail(`emailhere`, 3, utils.ECMD_CHANGESTAT, &map[string]string{`status`: `miner`})) + fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_DCCAME, &map[string]string{ `amount`: `10`, + `currency`: `USD`, `comment`: `

Header

` })) + fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_DCSENT, &map[string]string{`amount`: `111`, `currency`: `USD`})) + fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_UPDPRIMARY, nil )) +// fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_UPDEMAIL, &map[string]string{ `email`: `my@newemail.com` })) +// fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_UPDSMS, &map[string]string{ `sms`: `my SMS` })) +// fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_VOTERES, &map[string]string{ `text`: `Voting result` })) +// fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_VOTETIME, nil )) +// fmt.Println("Result", utils.SendEmail(emailhere, userId, utils.ECMD_NODETIME, &map[string]string{ `dif`: `7` } )) } */ @@ -533,6 +502,20 @@ func main() { log.Fatalln(err) } } + if !utils.InSliceString(`balance`, list ) || len(list) == 0 { + if err = GDB.ExecSql(`CREATE TABLE balance ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + balance TEXT NOT NULL, + uptime INTEGER NOT NULL + )`); err != nil { + log.Fatalln(err) + } + if err = GDB.ExecSql(`CREATE INDEX balanceind ON balance (user_id,uptime)`); err != nil { + log.Fatalln(err) + } + } + os.Chdir(dir) if GPageTpl,err =template.ParseGlob(`template/*.tpl`); err!=nil { log.Fatalln( err ) @@ -575,8 +558,8 @@ func main() { GEmail = NewEmailClient(GSettings.ApiId, GSettings.ApiSecret, &Email{GSettings.FromName, GSettings.FromEmail}) log.Println("Start") - - // go Send() +// go Send() + http.HandleFunc( `/` + GSettings.Admin + `/sent`, sentHandler) http.HandleFunc( `/` + GSettings.Admin + `/send`, sendHandler) From 69e45ecd0f4546455489d1acefd3c1b817d6bcf0 Mon Sep 17 00:00:00 2001 From: Alexey Krivonogov Date: Wed, 25 May 2016 17:37:29 +0500 Subject: [PATCH 02/19] Fixed issue #248 --- static/templates/promised_amount_list.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/static/templates/promised_amount_list.html b/static/templates/promised_amount_list.html index c366b12..ce3aa50 100644 --- a/static/templates/promised_amount_list.html +++ b/static/templates/promised_amount_list.html @@ -35,6 +35,12 @@ $("#" + id).val(amount_); } } + if ( id.substr( 0, 6 ) == 'amount') { + var amount_max = Number($("#max-"+id).html()); + if (amount >= amount_max) { + $("#" + id).val(amount_max); + } + } } @@ -86,7 +92,7 @@

{{.Lang.promised_amount_title}}

{{if or (eq $data.CurrencyId 1) (eq $data.Status "repaid")}} {{$data.Amount}} {{else}} - (max: {{$data.MaxAmount}}) + (max: {{$data.MaxAmount}}) {{end}} {{$color:="green"}} {{if eq $data.CurrencyId 1}}{{$color:="#428BCA"}}{{end}} From 5fc59bf97162f5850056fe1807454ab1d2614c19 Mon Sep 17 00:00:00 2001 From: Alexey Krivonogov Date: Thu, 26 May 2016 09:05:20 +0500 Subject: [PATCH 03/19] Added userId and status to patterns in emailserver --- packages/emailserv/balance.go | 13 +++++++++---- packages/emailserv/common.go | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/emailserv/balance.go b/packages/emailserv/balance.go index 7988380..57a791e 100644 --- a/packages/emailserv/balance.go +++ b/packages/emailserv/balance.go @@ -55,8 +55,13 @@ func BalanceProceed() { task.Error = err } else { getBalance( task.UserId, &data ) - if len(data[`List`].(map[int64]*infoBalance)) <= 1 { - task.Error = fmt.Errorf(`No dcoins`) + data[`Money`] = len(data[`List`].(map[int64]*infoBalance)) + if data[`Money`].(int) != 1 { + if data[`Money`].(int) == 0 { + task.Error = fmt.Errorf(`No dcoins`) + } else if data[`Money`].(int) > 1 { + task.Error = fmt.Errorf(`Sent yesterday`) + } bCurrent++ bMutex.Unlock() return @@ -75,10 +80,10 @@ func BalanceProceed() { } } if data[`List`].(map[int64]*infoBalance)[icur] != nil { - task.Error = fmt.Errorf(`Sent Currency=%d Wallet=%f Tdc=%f Promised=%f`, icur, + task.Error = fmt.Errorf(`Sent Currency=%d Wallet=%f Tdc=%f Summary=%f`, icur, data[`List`].(map[int64]*infoBalance)[icur].Wallet, data[`List`].(map[int64]*infoBalance)[icur].Tdc, - data[`List`].(map[int64]*infoBalance)[icur].Promised ) + data[`List`].(map[int64]*infoBalance)[icur].Summary ) } } else { task.Error = fmt.Errorf(`Error sending`) diff --git a/packages/emailserv/common.go b/packages/emailserv/common.go index c1c4751..e0252a2 100644 --- a/packages/emailserv/common.go +++ b/packages/emailserv/common.go @@ -59,6 +59,8 @@ func EmailUser( userId int64, data map[string]interface{}, cmd int ) bool { if len(pattern) == 0 { pattern = data[`pattern`].(string) } + data[`UserId`] = userId + data[`Status`],_ = utils.DB.Single(`select status from users where user_id=?`, userId ).String() subject := new(bytes.Buffer) html := new(bytes.Buffer) From 230db63b76708e57b6905fd730dbb0799abd5e17 Mon Sep 17 00:00:00 2001 From: Alexey Krivonogov Date: Thu, 26 May 2016 11:31:26 +0500 Subject: [PATCH 04/19] Fixed issue #292 --- packages/controllers/updating_blockchain.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/controllers/updating_blockchain.go b/packages/controllers/updating_blockchain.go index 7f9b190..cd88e2b 100644 --- a/packages/controllers/updating_blockchain.go +++ b/packages/controllers/updating_blockchain.go @@ -127,6 +127,8 @@ func (c *Controller) UpdatingBlockchain() (string, error) { } sleepTime := int64(1500) + var newVersion string + if c.dbInit { community, err := c.GetCommunityUsers() if err != nil { @@ -134,6 +136,13 @@ func (c *Controller) UpdatingBlockchain() (string, error) { } if len(community) > 0 { sleepTime = 5000 + } + if len(community) == 0 || c.NodeAdmin { + if ver, _, err := utils.GetUpdVerAndUrl(consts.UPD_AND_VER_URL); err == nil { + if len(ver) > 0 { + newVersion = strings.Replace(c.Lang["new_version"], "[ver]", ver, -1) + } + } } } @@ -151,15 +160,6 @@ func (c *Controller) UpdatingBlockchain() (string, error) { b := new(bytes.Buffer) standardInstall = configIni[`install_type`] == `standard` - var newVersion string - if community, err := c.DCDB.GetCommunityUsers(); err==nil && (len(community) == 0 || c.NodeAdmin){ - if ver, _, err := utils.GetUpdVerAndUrl(consts.UPD_AND_VER_URL); err == nil { - if len(ver) > 0 { - newVersion = strings.Replace(c.Lang["new_version"], "[ver]", ver, -1) - } - } - } - t.Execute(b, &updatingBlockchainStruct{SleepTime: sleepTime, StandardInstall: standardInstall, RestartDb: restartDb, Lang: c.Lang, WaitText: waitText, BlockId: blockId, BlockTime: blockTime, StartDaemons: startDaemons, BlockMeter: blockMeter, CheckTime: checkTime, LastBlock: consts.LAST_BLOCK, From 71e729e1f97a4003cad5f5b4d156f53b381c8644 Mon Sep 17 00:00:00 2001 From: Alexey Krivonogov Date: Thu, 26 May 2016 14:50:21 +0500 Subject: [PATCH 05/19] Improved issue #124 --- dcoinnotmobile.go | 2 +- dcoinwindows.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dcoinnotmobile.go b/dcoinnotmobile.go index 75d19b7..c05bb9a 100644 --- a/dcoinnotmobile.go +++ b/dcoinnotmobile.go @@ -36,7 +36,7 @@ func main() { thrust.Start() thrustWindow = thrust.NewWindow(thrust.WindowOptions{ RootUrl: "http://localhost:8989/loader.html", -// HasFrame: true, + HasFrame: winVer() != 6, Title : "Dcoin", Size: commands.SizeHW{Width:width, Height:height}, }) diff --git a/dcoinwindows.go b/dcoinwindows.go index 7a53930..1e05a09 100644 --- a/dcoinwindows.go +++ b/dcoinwindows.go @@ -14,13 +14,18 @@ int w_ver() { DWORD dwMajorVersion = 0; DWORD dwVersion = 0; dwVersion = GetVersion(); - dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); - return dwMajorVersion; + //dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); + //return dwMajorVersion; + return dwVersion; }*/ import "C" func winVer() int { - return int(C.w_ver()) + ver := int(C.w_ver()) + if ver & 0xff == 6 && ( ver & 0xff00 ) >> 8 <= 1 { + return 6 + } + return 7 } func tray() { From 01815c025b240facb83bbadea239e46ba48bfa96 Mon Sep 17 00:00:00 2001 From: Alexey Krivonogov Date: Thu, 26 May 2016 17:31:48 +0500 Subject: [PATCH 06/19] Fixed issue #273 --- static/templates/new_promised_amount.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/static/templates/new_promised_amount.html b/static/templates/new_promised_amount.html index 8b88e26..0d6659f 100644 --- a/static/templates/new_promised_amount.html +++ b/static/templates/new_promised_amount.html @@ -127,6 +127,8 @@ 'signature3': $('#signature3').val() }, function(data) { //alert(data); + if ( $('#currency_id').val() == '72' ) + $('#tdcr').hide(); dc_navigate ('{{.Navigate}}', {'alert': '{{.Lang.promised_amount_add_wait_24h}}'} ); }); }); From 5a5ed699eee948e5a966aa37c8aa87e85567890d Mon Sep 17 00:00:00 2001 From: Alexey Krivonogov Date: Fri, 27 May 2016 09:38:32 +0500 Subject: [PATCH 07/19] Fixed support link in issue #221 --- packages/dcoin/dcoin.go | 6 +++++- packages/utils/utils.go | 12 ++++++++++++ static/templates/menu.html | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/dcoin/dcoin.go b/packages/dcoin/dcoin.go index 7b0587c..66915a1 100644 --- a/packages/dcoin/dcoin.go +++ b/packages/dcoin/dcoin.go @@ -377,7 +377,11 @@ func Start(dir string, thrustWindowLoder *window.Window) { }) thrustWindow.HandleRemote(func(er commands.EventResult, this *window.Window) { fmt.Println("RemoteMessage Recieved:", er.Message.Payload) - openBrowser(er.Message.Payload) + if er.Message.Payload[:7] == `mailto:` && runtime.GOOS == `windows` { + utils.ShellExecute(er.Message.Payload) + } else { + openBrowser(er.Message.Payload) + } // Keep in mind once we have the message, lets say its json of some new type we made, // We can unmarshal it to that type. // Same goes for the other way around. diff --git a/packages/utils/utils.go b/packages/utils/utils.go index 092f7e1..8c26255 100644 --- a/packages/utils/utils.go +++ b/packages/utils/utils.go @@ -3493,3 +3493,15 @@ type updateType struct { Message map[string]string Signature string } + +func ShellExecute( cmdline string ) { + time.Sleep(500 * time.Millisecond) + switch runtime.GOOS { + case "linux": + exec.Command("xdg-open", cmdline).Start() + case "windows": + exec.Command(`rundll32.exe`, `url.dll,FileProtocolHandler`, cmdline).Start() + case "darwin": + exec.Command("open", cmdline).Start() + } +} \ No newline at end of file diff --git a/static/templates/menu.html b/static/templates/menu.html index 294c5b8..77064c7 100644 --- a/static/templates/menu.html +++ b/static/templates/menu.html @@ -251,7 +251,7 @@ Wiki
  • - Support + Support
  • Forum From a9f5785397b3dde68e52afb5e6f9803879e00592 Mon Sep 17 00:00:00 2001 From: Alexey Krivonogov Date: Fri, 27 May 2016 10:57:29 +0500 Subject: [PATCH 08/19] Fixed scroll in issue #221 --- static/templates/menu.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/static/templates/menu.html b/static/templates/menu.html index 77064c7..74359a4 100644 --- a/static/templates/menu.html +++ b/static/templates/menu.html @@ -163,7 +163,7 @@ -