Skip to content

Commit

Permalink
Update to latest nightly, fix formatting and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rien committed Mar 16, 2021
1 parent 8c16a36 commit 1817736
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 84 deletions.
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let
};
# the rls is missing on the nightly build of 2020-09-29, so pinning a date for the moment
rustNightlyTemp = (pkgs.rustChannelOf{
date = "2020-09-28";
date = "2021-03-15";
channel = "nightly";
}).rust.override {
extensions = [ "rustfmt-preview" "rls-preview" "rust-src" "rust-analyzer-preview" ];
Expand Down
6 changes: 2 additions & 4 deletions src/controllers/clients_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use crate::DbConn;
pub fn list_clients(
conn: DbConn,
session: AdminSession,
) -> Result<impl Responder<'static>>
{
) -> Result<impl Responder<'static>> {
let clients = Client::all(&conn)?;
Ok(Accepter {
html: template! {
Expand All @@ -32,8 +31,7 @@ pub fn create_client(
client: Api<NewClient>,
conn: DbConn,
_admin: AdminSession,
) -> Result<impl Responder<'static>>
{
) -> Result<impl Responder<'static>> {
let client = Client::create(client.into_inner(), &conn)?;
Ok(Accepter {
html: Redirect::to(uri!(list_clients)),
Expand Down
18 changes: 6 additions & 12 deletions src/controllers/oauth_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ impl AuthState {
pub fn from_req(
client: Client,
auth_req: AuthorizationRequest,
) -> AuthState
{
) -> AuthState {
AuthState {
client_id: client.id,
client_name: client.name,
Expand Down Expand Up @@ -96,8 +95,7 @@ pub fn authorize(
mut cookies: Cookies,
req: Form<AuthorizationRequest>,
conn: DbConn,
) -> Result<Redirect>
{
) -> Result<Redirect> {
let req = req.into_inner();
if !req.response_type.eq("code") {
// This was NotImplemented error, but it makes no sense for a authorise
Expand Down Expand Up @@ -145,8 +143,7 @@ pub fn grant_get<'a>(
cookies: Cookies,
token_store: State<TokenStore<UserToken>>,
conn: DbConn,
) -> Result<Either<impl Responder<'static>, impl Responder<'static>>>
{
) -> Result<Either<impl Responder<'static>, impl Responder<'static>>> {
let state = AuthState::from_cookies(cookies)?;
if let Ok(client) = Client::find(state.client_id, &conn) {
if client.needs_grant {
Expand All @@ -172,8 +169,7 @@ pub fn grant_post(
cookies: Cookies,
form: Form<GrantFormData>,
token_store: State<TokenStore<UserToken>>,
) -> Result<Redirect>
{
) -> Result<Redirect> {
let data = form.into_inner();
let state = AuthState::from_cookies(cookies)?;
if data.grant {
Expand All @@ -191,8 +187,7 @@ fn authorization_granted(
state: AuthState,
user: User,
token_store: &TokenStore<UserToken>,
) -> Redirect
{
) -> Redirect {
let authorization_code = token_store.create_token(UserToken {
user_id: user.id,
username: user.username.clone(),
Expand Down Expand Up @@ -247,8 +242,7 @@ pub fn token(
form: Form<TokenFormData>,
token_state: State<TokenStore<UserToken>>,
conn: DbConn,
) -> Result<Json<TokenSuccess>>
{
) -> Result<Json<TokenSuccess>> {
let data = form.into_inner();
let token = data.code.clone();
let token_store = token_state.inner();
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/pages_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use crate::DbConn;
pub fn home_page(
session: Option<UserSession>,
conn: DbConn,
) -> Result<Either<Redirect, impl Responder<'static>>>
{
) -> Result<Either<Redirect, impl Responder<'static>>> {
match session {
None => Ok(Either::Right(template! {
"pages/home.html";
Expand Down
6 changes: 2 additions & 4 deletions src/controllers/sessions_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use crate::DbConn;
pub fn new_session(
session: Option<UserSession>,
cookies: Cookies,
) -> Either<Redirect, impl Responder<'static>>
{
) -> Either<Redirect, impl Responder<'static>> {
match session {
None => Either::Right(template! {
"session/login.html";
Expand Down Expand Up @@ -42,8 +41,7 @@ pub fn create_session(
form: Form<LoginFormData>,
mut cookies: Cookies,
conn: DbConn,
) -> Result<Either<Redirect, impl Responder<'static>>>
{
) -> Result<Either<Redirect, impl Responder<'static>>> {
let form = form.into_inner();
match User::find_and_authenticate(&form.username, &form.password, &conn) {
Err(ZauthError::LoginError(login_error)) => {
Expand Down
24 changes: 8 additions & 16 deletions src/controllers/users_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ pub fn show_user(
session: UserSession,
conn: DbConn,
id: i32,
) -> Result<impl Responder<'static>>
{
) -> Result<impl Responder<'static>> {
let user = User::find(id, &conn)?;
// Check whether the current session is allowed to view this user
if session.user.admin || session.user.id == id {
Expand All @@ -53,8 +52,7 @@ pub fn show_user(
pub fn list_users(
session: UserSession,
conn: DbConn,
) -> Result<impl Responder<'static>>
{
) -> Result<impl Responder<'static>> {
let users = User::all(&conn)?;
Ok(Accepter {
html: template! {
Expand All @@ -72,8 +70,7 @@ pub fn create_user(
user: Api<NewUser>,
conn: DbConn,
config: State<Config>,
) -> Result<impl Responder<'static>>
{
) -> Result<impl Responder<'static>> {
let user = User::create(user.into_inner(), config.bcrypt_cost, &conn)
.map_err(ZauthError::from)?;
Ok(Accepter {
Expand All @@ -94,8 +91,7 @@ pub fn register(
user: Api<NewUser>,
conf: State<Config>,
conn: DbConn,
) -> Result<Either<impl Responder<'static>, impl Responder<'static>>>
{
) -> Result<Either<impl Responder<'static>, impl Responder<'static>>> {
match User::create_pending(user.into_inner(), conf.bcrypt_cost, &conn) {
Ok(user) => Ok(Left(Accepter {
html: Custom(
Expand Down Expand Up @@ -127,8 +123,7 @@ pub fn update_user(
conn: DbConn,
) -> Result<
Either<impl Responder<'static>, Custom<impl Debug + Responder<'static>>>,
>
{
> {
let mut user = User::find(id, &conn)?;
if session.user.id == user.id || session.user.admin {
user.change_with(change.into_inner(), conf.bcrypt_cost)?;
Expand All @@ -148,8 +143,7 @@ pub fn set_admin(
value: Api<ChangeAdmin>,
_session: AdminSession,
conn: DbConn,
) -> Result<impl Responder<'static>>
{
) -> Result<impl Responder<'static>> {
let mut user = User::find(id, &conn)?;
user.admin = value.into_inner().admin;
let user = user.update(&conn)?;
Expand All @@ -174,8 +168,7 @@ pub fn forgot_password_post(
value: Form<ResetPassword>,
conn: DbConn,
mailer: State<Mailer>,
) -> Result<impl Responder<'static>>
{
) -> Result<impl Responder<'static>> {
let for_email = value.into_inner().for_email;

let user = match User::find_by_email(&for_email, &conn) {
Expand Down Expand Up @@ -233,8 +226,7 @@ pub fn reset_password_post(
conn: DbConn,
conf: State<Config>,
mailer: State<Mailer>,
) -> Result<impl Responder<'static>>
{
) -> Result<impl Responder<'static>> {
let form = form.into_inner();
if let Some(user) = User::find_by_token(&form.token, &conn)? {
match user.change_password(&form.new_password, conf.bcrypt_cost, &conn)
Expand Down
6 changes: 2 additions & 4 deletions src/ephemeral/from_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ where
fn transform(
request: &Request,
data: Data,
) -> Transform<Outcome<Self::Owned, Self::Error>>
{
) -> Transform<Outcome<Self::Owned, Self::Error>> {
if request.content_type() == Some(&ContentType::Form) {
match Form::transform(request, data) {
Transform::Borrowed(o) => Transform::Borrowed(
Expand Down Expand Up @@ -68,8 +67,7 @@ where
fn from_data(
request: &Request,
outcome: Transformed<'a, Self>,
) -> Outcome<Self, Self::Error>
{
) -> Outcome<Self, Self::Error> {
if request.content_type() == Some(&ContentType::Form) {
let outcome = match outcome {
Transform::Borrowed(o) => {
Expand Down
3 changes: 1 addition & 2 deletions src/ephemeral/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const SESSION_COOKIE: &str = "ZAUTH_SESSION";
pub fn ensure_logged_in_and_redirect(
mut cookies: Cookies,
uri: Origin,
) -> Redirect
{
) -> Redirect {
cookies.add_private(Cookie::new(REDIRECT_COOKIE, uri.to_string()));
Redirect::to(uri!(new_session))
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ fn create_admin(
rocket: Rocket,
config: Config,
password: String,
) -> std::result::Result<Rocket, Rocket>
{
) -> std::result::Result<Rocket, Rocket> {
let username = String::from("admin");
let conn = DbConn::get_one(&rocket).expect("database connection");
let admin = User::find_by_username(&username, &conn)
Expand Down
15 changes: 5 additions & 10 deletions src/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ impl Mailer {
user: &User,
subject: String,
text: String,
) -> Result<Message>
{
) -> Result<Message> {
Ok(Message::builder()
.to(user.try_into()?)
.subject(subject)
Expand All @@ -41,8 +40,7 @@ impl Mailer {
user: &User,
subject: String,
text: String,
) -> Result<()>
{
) -> Result<()> {
let email = self.build(user, subject, text)?;
self.queue
.try_send(email)
Expand All @@ -54,8 +52,7 @@ impl Mailer {
user: &User,
subject: String,
text: String,
) -> Result<()>
{
) -> Result<()> {
let mail = self.build(user, subject, text)?;

self.queue
Expand Down Expand Up @@ -85,8 +82,7 @@ impl Mailer {
fn stub_sender(
wait: Duration,
receiver: Receiver<Message>,
) -> impl FnOnce()
{
) -> impl FnOnce() {
move || {
while let Ok(mail) = receiver.recv() {
{
Expand All @@ -109,8 +105,7 @@ impl Mailer {
wait: Duration,
receiver: Receiver<Message>,
server: &str,
) -> Result<impl FnOnce()>
{
) -> Result<impl FnOnce()> {
let transport = SmtpTransport::relay(server)
.map_err(LaunchError::from)?
.build();
Expand Down
11 changes: 4 additions & 7 deletions src/models/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub struct NewClient {
pub redirect_uri_list: String,
}

#[table_name = "clients"]
#[derive(Insertable, Debug, Clone)]
#[table_name = "clients"]
pub struct NewClientWithSecret {
pub name: String,
pub needs_grant: bool,
Expand All @@ -66,8 +66,7 @@ impl Client {
pub fn create(
client: NewClient,
conn: &ConcreteConnection,
) -> Result<Client>
{
) -> Result<Client> {
let client = NewClientWithSecret {
name: client.name,
needs_grant: client.needs_grant,
Expand All @@ -90,8 +89,7 @@ impl Client {
pub fn find_by_name(
name: &str,
conn: &ConcreteConnection,
) -> Result<Client>
{
) -> Result<Client> {
let client =
clients::table.filter(clients::name.eq(name)).first(conn)?;
Ok(client)
Expand All @@ -112,8 +110,7 @@ impl Client {
name: &str,
secret: &str,
conn: &ConcreteConnection,
) -> Result<Client>
{
) -> Result<Client> {
let client = Self::find_by_name(name, conn)?;
if client.secret == secret {
Ok(client)
Expand Down
Loading

0 comments on commit 1817736

Please sign in to comment.