mirror of
				https://github.com/nitnelave/lldap.git
				synced 2023-04-12 14:25:13 +00:00 
			
		
		
		
	app: disable the login button while logging in
This commit is contained in:
		
							parent
							
								
									4f3b8f17b7
								
							
						
					
					
						commit
						2994f6d168
					
				@ -13,7 +13,7 @@ pub struct LoginForm {
 | 
				
			|||||||
    error: Option<anyhow::Error>,
 | 
					    error: Option<anyhow::Error>,
 | 
				
			||||||
    form: Form<FormModel>,
 | 
					    form: Form<FormModel>,
 | 
				
			||||||
    // Used to keep the request alive long enough.
 | 
					    // Used to keep the request alive long enough.
 | 
				
			||||||
    _task: Option<FetchTask>,
 | 
					    task: Option<FetchTask>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// The fields of the form, with the constraints.
 | 
					/// The fields of the form, with the constraints.
 | 
				
			||||||
@ -59,12 +59,12 @@ impl LoginForm {
 | 
				
			|||||||
                    username,
 | 
					                    username,
 | 
				
			||||||
                    login_start_request: message,
 | 
					                    login_start_request: message,
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
                self._task = Some(HostService::login_start(
 | 
					                self.task = Some(HostService::login_start(
 | 
				
			||||||
                    req,
 | 
					                    req,
 | 
				
			||||||
                    self.link
 | 
					                    self.link
 | 
				
			||||||
                        .callback_once(move |r| Msg::AuthenticationStartResponse((state, r))),
 | 
					                        .callback_once(move |r| Msg::AuthenticationStartResponse((state, r))),
 | 
				
			||||||
                )?);
 | 
					                )?);
 | 
				
			||||||
                Ok(false)
 | 
					                Ok(true)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Msg::AuthenticationStartResponse((login_start, res)) => {
 | 
					            Msg::AuthenticationStartResponse((login_start, res)) => {
 | 
				
			||||||
                let res = res.context("Could not log in (invalid response to login start)")?;
 | 
					                let res = res.context("Could not log in (invalid response to login start)")?;
 | 
				
			||||||
@ -84,13 +84,14 @@ impl LoginForm {
 | 
				
			|||||||
                    server_data: res.server_data,
 | 
					                    server_data: res.server_data,
 | 
				
			||||||
                    credential_finalization: login_finish.message,
 | 
					                    credential_finalization: login_finish.message,
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
                self._task = Some(HostService::login_finish(
 | 
					                self.task = Some(HostService::login_finish(
 | 
				
			||||||
                    req,
 | 
					                    req,
 | 
				
			||||||
                    self.link.callback_once(Msg::AuthenticationFinishResponse),
 | 
					                    self.link.callback_once(Msg::AuthenticationFinishResponse),
 | 
				
			||||||
                )?);
 | 
					                )?);
 | 
				
			||||||
                Ok(false)
 | 
					                Ok(false)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Msg::AuthenticationFinishResponse(user_info) => {
 | 
					            Msg::AuthenticationFinishResponse(user_info) => {
 | 
				
			||||||
 | 
					                self.task = None;
 | 
				
			||||||
                self.on_logged_in
 | 
					                self.on_logged_in
 | 
				
			||||||
                    .emit(user_info.context("Could not log in")?);
 | 
					                    .emit(user_info.context("Could not log in")?);
 | 
				
			||||||
                Ok(true)
 | 
					                Ok(true)
 | 
				
			||||||
@ -109,7 +110,7 @@ impl Component for LoginForm {
 | 
				
			|||||||
            on_logged_in: props.on_logged_in,
 | 
					            on_logged_in: props.on_logged_in,
 | 
				
			||||||
            error: None,
 | 
					            error: None,
 | 
				
			||||||
            form: Form::<FormModel>::new(FormModel::default()),
 | 
					            form: Form::<FormModel>::new(FormModel::default()),
 | 
				
			||||||
            _task: None,
 | 
					            task: None,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -119,6 +120,7 @@ impl Component for LoginForm {
 | 
				
			|||||||
            Err(e) => {
 | 
					            Err(e) => {
 | 
				
			||||||
                ConsoleService::error(&e.to_string());
 | 
					                ConsoleService::error(&e.to_string());
 | 
				
			||||||
                self.error = Some(e);
 | 
					                self.error = Some(e);
 | 
				
			||||||
 | 
					                self.task = None;
 | 
				
			||||||
                true
 | 
					                true
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Ok(b) => b,
 | 
					            Ok(b) => b,
 | 
				
			||||||
@ -170,6 +172,7 @@ impl Component for LoginForm {
 | 
				
			|||||||
                  <button
 | 
					                  <button
 | 
				
			||||||
                    type="submit"
 | 
					                    type="submit"
 | 
				
			||||||
                    class="btn btn-primary"
 | 
					                    class="btn btn-primary"
 | 
				
			||||||
 | 
					                    disabled=self.task.is_some()
 | 
				
			||||||
                    onclick=self.link.callback(|e: MouseEvent| {e.prevent_default(); Msg::Submit})>
 | 
					                    onclick=self.link.callback(|e: MouseEvent| {e.prevent_default(); Msg::Submit})>
 | 
				
			||||||
                    {"Login"}
 | 
					                    {"Login"}
 | 
				
			||||||
                  </button>
 | 
					                  </button>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user