File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- use crate :: { rpc , settings, verbosity, Result } ;
1+ use crate :: { settings, verbosity, Result } ;
22use clap:: Args ;
33use colored_json:: ToColoredJson ;
44use serde_json:: json;
@@ -28,22 +28,7 @@ pub struct LoginArgs {
2828}
2929
3030pub fn login ( args : & LoginArgs ) -> Result < ( ) > {
31- let old_password = settings:: get_str ( "password" ) ?;
32- settings:: put_str ( "password" , & args. password ) ?;
33- match rpc:: call ( "get_area" , json ! ( { "id" : "th" } ) ) {
34- Ok ( res) => match res. error {
35- Some ( _) => {
36- res. print ( ) ?;
37- settings:: put_str ( "password" , & old_password) ?;
38- Err ( "Password is likely wrong" ) ?
39- }
40- None => Ok ( ( ) ) ,
41- } ,
42- Err ( e) => {
43- settings:: put_str ( "password" , & old_password) ?;
44- Err ( e) ?
45- }
46- }
31+ settings:: put_str ( "password" , & args. password )
4732}
4833
4934#[ derive( Args ) ]
Original file line number Diff line number Diff line change @@ -27,17 +27,16 @@ impl RpcResponse {
2727 }
2828}
2929
30- pub fn call ( method : & str , mut params : Value ) -> Result < RpcResponse > {
30+ pub fn call ( method : & str , params : Value ) -> Result < RpcResponse > {
3131 if verbosity ( ) > 0 {
3232 println ! (
3333 "{}" ,
3434 serde_json:: to_string( & params) ?. to_colored_json_auto( ) ?
3535 ) ;
3636 }
3737 let params = params
38- . as_object_mut ( )
38+ . as_object ( )
3939 . ok_or ( "params value is not a valid JSON object" ) ?;
40- params. insert ( "password" . into ( ) , settings:: get_str ( "password" ) ?. into ( ) ) ;
4140 let args = json ! (
4241 { "jsonrpc" : "2.0" , "method" : method, "params" : params, "id" : 1 }
4342 ) ;
@@ -49,7 +48,11 @@ pub fn call(method: &str, mut params: Value) -> Result<RpcResponse> {
4948 println ! ( "{}" , serde_json:: to_string( & args) ?. to_colored_json_auto( ) ?) ;
5049 }
5150 let response = ureq:: post ( api_url)
52- //.header("Content-Type", "application/json")
51+ . header ( "Content-Type" , "application/json" )
52+ . header (
53+ "Authorization" ,
54+ format ! ( "Bearer {}" , settings:: get_str( "password" ) ?) ,
55+ )
5356 . send_json ( args) ?
5457 . body_mut ( )
5558 . read_to_string ( ) ?;
You can’t perform that action at this time.
0 commit comments