Ejemplo n.º 1
0
// Get token
func AuthLogin(w http.ResponseWriter, r *http.Request) {
	user := r.FormValue("User")
	password := r.FormValue("Password")

	response, err := appauth.ProcessAppAuth([]string{"0", "appauth", "2", user, password})
	Response(response, err, w, r)
	return
}
Ejemplo n.º 2
0
// Create auth account
func AuthCreate(w http.ResponseWriter, r *http.Request) {
	userID := r.FormValue("UserIdentificationNumber")
	password := r.FormValue("Password")

	response, err := appauth.ProcessAppAuth([]string{"0", "appauth", "3", userID, password})
	Response(response, err, w, r)
	return
}
Ejemplo n.º 3
0
// Extend token
func AuthIndex(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}

	//Extend token
	response, err := appauth.ProcessAppAuth([]string{token, "appauth", "1"})
	Response(response, err, w, r)
	return
}
Ejemplo n.º 4
0
// Remove auth account
func AuthRemove(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}

	user := r.FormValue("User")
	password := r.FormValue("Password")

	response, err := appauth.ProcessAppAuth([]string{token, "appauth", "4", user, password})
	Response(response, err, w, r)
	return
}
Ejemplo n.º 5
0
Archivo: server.go Proyecto: BVNK/bank
func processCommand(text string) (result interface{}, err error) {
	// Commands are received split by tilde (~)
	// command~DATA
	cleanText := strings.Replace(text, "\n", "", -1)
	fmt.Printf("### %s ####\n", cleanText)
	command := strings.Split(cleanText, "~")

	// Check if we received a command
	if len(command) == 0 {
		fmt.Println("No command received")
		return
	}

	// Remove null termination from data
	command[len(command)-1] = string(bytes.Trim([]byte(command[len(command)-1]), "\x00"))

	// Check application auth. This is always the first value, if no token a 0 is sent
	isCreateAccount := (command[0] == "0" && command[1] == "acmt" && command[2] == "1")
	isLogIn := (command[0] == "0" && command[1] == "appauth" && command[2] == "2")
	isCreateUserPassword := (command[0] == "0" && command[1] == "appauth" && command[2] == "3")

	if !isCreateAccount || !isLogIn || !isCreateUserPassword {
		err := appauth.CheckToken(command[0])
		if err != nil {
			return "", errors.New("server.processCommand: " + err.Error())
		}
	}

	switch command[1] {
	case "appauth":
		// Check "help"
		if command[2] == "help" {
			return "Format of appauth: appauth~userName~password", nil
		}
		result, err = appauth.ProcessAppAuth(command)
		if err != nil {
			return "", errors.New("server.processCommand: " + err.Error())
		}
		break
	case "pain":
		// Check "help"
		if command[2] == "help" {
			return "Format of PAIN transaction:\npain\npainType~senderAccountNumber@SenderBankNumber\nreceiverAccountNumber@ReceiverBankNumber\ntransactionAmount\n\nBank numbers may be left void if bank is local", nil
		}
		result, err = transactions.ProcessPAIN(command)
		if err != nil {
			return "", errors.New("server.processCommand: " + err.Error())
		}
	case "camt":
	case "acmt":
		// Check "help"
		if command[2] == "help" {
			return "", nil // @TODO Help section
		}
		result, err = accounts.ProcessAccount(command)
	case "remt":
	case "reda":
	case "pacs":
	case "auth":
		break
	default:
		return "No valid command received", nil
	}

	return
}