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
| func (s *Server) Login(t trans.Transmitable) (cs.User, int) { chRate := time.Tick(1e3) var recvL int64 = 0 var err error recvL, err = t.RecvUntil(int64(24), recvL, chRate) if err != nil { fmt.Println("1 error:", err.Error()) return nil, -1 } srcLength := auth.BytesToInt64(t.GetBuf()[:8]) encLength := auth.BytesToInt64(t.GetBuf()[8:16]) nmLength := auth.BytesToInt64(t.GetBuf()[16:24]) recvL, err = t.RecvUntil(encLength, recvL, chRate) if err != nil { fmt.Println("2 error:", err.Error()) return nil, -1 } var nameApass []byte nameApass, err = auth.AesDecode(t.GetBuf()[24:24+encLength], srcLength, t.GetBlock()) if err != nil { fmt.Println("decode error:", err.Error()) return nil, -1 } fmt.Println(string(nameApass[:nmLength]), string(nameApass[nmLength:]))
pc := cs.UserIndexByName(s.loginUserList, string(nameApass[:nmLength])) if pc != nil { fmt.Println("userfined, ", pc.GetUsername()) fmt.Println("pc token is ", pc.GetToken()) if pc.GetToken() != string(nameApass[nmLength:]) { fmt.Println("token verify error! not valid!") return nil, -1 } else { if pc.GetInfos() == nil { pc.SetInfos(t) return pc, 2 } else { return pc, 1 } } } username := string(nameApass[:nmLength]) row := s.db.QueryRow(fmt.Sprintf("SELECT * FROM cuser where username='%s'", username)) if row == nil { return nil, -1 } var uid int var susername string var spassword string var screated string
err = row.Scan(&uid, &susername, &spassword, &screated) if err != nil || spassword != strings.ToUpper(string(nameApass[nmLength:])) { return nil, -1 } rc := cs.NewCUser(string(nameApass[:nmLength]), int64(uid), "/") if rc == nil { return nil, -1 } rc.SetListener(t) rows, err := s.db.Query(fmt.Sprintf("SELECT cfileid FROM ufile where ownerid=%d", uid)) if err != nil { return nil, -1 } defer rows.Close() var cid, size int var totalSize int64 = 0 for rows.Next() { err = rows.Scan(&cid) if err != nil || cid < 0{ continue } row = s.db.QueryRow(fmt.Sprintf("select size from cfile where uid=%d", cid)) if row == nil { continue } err = row.Scan(&size) if err != nil { continue } totalSize += int64(size) } rc.SetUsed(int64(totalSize)) return rc, 0 }
|