func PerformActions(params *revel.Params, serverInterface models.ServerInterface) { var action = strings.ToLower(params.Get("action")) switch action { case "start": serverInterface.Start() case "stop": serverInterface.Stop() case "run": serverInterface.Run() } }
func bindCard(params *revel.Params, name string, typ reflect.Type) reflect.Value { var card models.Card if name == "card" && typ == reflect.TypeOf(card) { params.Bind(&card.CardBody, "CardBody") params.Bind(&card.CardBlanks, "CardBlanks") params.Bind(&card.CardType, "CardType") return reflect.ValueOf(card) } return reflect.ValueOf(nil) }
func (a *LinkedinAuthProvider) AuthenticateBase(parent *AuthProvider, params *revel.Params) (resp AuthResponse, err error) { // assumption: validation has previously been done revel.OnAppStart() and then in in Authenticate() errorCode := params.Get("error") if errorCode != "" { resp = AuthResponse{Type: AuthResponseError, Response: params.Get("error_description")} return resp, err } code := params.Get("code") if code == "" { // we have no token, so begin authorization theUrl, _ := url.ParseRequestURI(parent.AuthConfig.AuthorizeUrl) // create a Map of all necessary params to pass to authenticator valueMap, _ := parent.MapAuthInitatorValues(parent) valueMap.Add("state", "blahblahblah") theUrl.RawQuery = valueMap.Encode() resp = AuthResponse{Type: AuthResponseRedirect, Response: theUrl.String()} return resp, err } else { // we have a code, so it's exchange time! theUrl, _ := url.ParseRequestURI(parent.AuthConfig.AccessTokenUrl) // create a map of all necessary params to pass to authenticator valueMap, _ := parent.MapExchangeValues(parent) valueMap.Add("code", code) valueMap.Add("state", "blahblahblah") // push the whole valueMap into the URL instance theUrl.RawQuery = valueMap.Encode() // do the POST, then post theJson, err := postRequestForJson(theUrl.Scheme+"://"+theUrl.Host+theUrl.Path, valueMap.Encode()) if err == nil { resp = AuthResponse{Type: AuthResponseString, Response: theJson} return resp, err } else { resp = AuthResponse{Type: AuthResponseError, Response: err.Error()} return resp, err } } }
func (a *TwitterAuthProvider) AuthenticateBase(parent *AuthProvider, params *revel.Params) (resp AuthResponse, err error) { // assumption: validation has previously been done revel.OnAppStart() and then in in Authenticate() errorCode := params.Get("error_code") if errorCode != "" { resp = AuthResponse{Type: AuthResponseError, Response: params.Get("error_message")} return resp, err } token := params.Get("oauth_token") verifier := params.Get("oauth_verifier") if token == "" && verifier == "" { // Step 1: obtain a request token and redirect user theUrl, _ := url.ParseRequestURI(parent.AuthConfig.RequestTokenUrl) // create a Map of all necessary params to pass to authenticator valueMap, _ := parent.MapAuthInitatorValues(parent) theUrl.RawQuery = valueMap.Encode() // do the POST to get the oauth_token theJson, err := postRequestForJson(theUrl.Scheme+"://"+theUrl.Host+theUrl.Path, valueMap.Encode()) if err != nil { resp = AuthResponse{Type: AuthResponseError, Response: err.Error()} return resp, err } // extract oauth_token out of theJson (which is not JSON, but rather a querystring) vals, err := url.ParseQuery(theJson) if err != nil { resp = AuthResponse{Type: AuthResponseError, Response: err.Error()} return resp, err } token := vals.Get("oauth_token") if token == "" { resp = AuthResponse{Type: AuthResponseError, Response: "No oauth token found in token request to Twitter."} return resp, err } // redirect user to authenticate redirectUrl, _ := url.ParseRequestURI(parent.AuthConfig.AuthorizeUrl) v := url.Values{} v.Set("oauth_token", token) redirectUrl.RawQuery = v.Encode() resp = AuthResponse{Type: AuthResponseRedirect, Response: redirectUrl.String()} return resp, err } else { // we have a token and verifier, so it's exchange time! theUrl, _ := url.ParseRequestURI(parent.AuthConfig.AccessTokenUrl) // create a map of all necessary params to pass to authenticator //valueMap, _ := parent.MapExchangeValues(parent) valueMap := url.Values{} valueMap.Add("oauth_token", token) valueMap.Add("oauth_verifier", verifier) // push the whole valueMap into the URL instance theUrl.RawQuery = valueMap.Encode() // do the POST, then post theJson, err := postRequestForJson(theUrl.Scheme+"://"+theUrl.Host+theUrl.Path, valueMap.Encode()) if err == nil { resp = AuthResponse{Type: AuthResponseString, Response: theJson} return resp, err } else { resp = AuthResponse{Type: AuthResponseError, Response: err.Error()} return resp, err } } }
func NewServerFromParams(Params *revel.Params) (server *Server) { server = &Server{ Label: Params.Get("label"), Username: Params.Get("username"), Host: Params.Get("host"), Port: Params.Get("port"), } queryInterval, err := strconv.Atoi(Params.Get("query_interval")) if err != nil { server.SetQueryInterval(60) } else { server.SetQueryInterval(queryInterval) } server.ParsePrivateKey(Params.Get("private_key")) server.SetPassword(Params.Get("password")) var cmds [][]string Params.Bind(&cmds, "commands") server.Commands = make(map[string]string) for _, cmd := range cmds { if len(cmd) == 2 && cmd[0] != "" && cmd[1] != "" { server.Commands[cmd[0]] = cmd[1] } } return }