密码错误时登录错误

时间:2017-02-03 01:38:09

标签: c# login uwp

我在进入商店页面之前创建了应用程序,然后需要先登录。所以先检查一下。登录后,它可以直接导航到商店页面。但是如果没有登录,用户必须登录,点击登录按钮后,它将导航到“商店”页面。同样,如果您想导航到“Koleksi”页面。

我遇到了问题,即使密码错误,仍然可以登录商店页面或“Koleksi”页面。当我添加导航到商店页面或“Koleksi”页面的功能时会发生这种情况。在添加功能之前,如果密码错误,则无法登录。 XAML:

LocalBroadcastManager.getInstance(this).unregisterReceiver(br);

代码:

<Image x:Name="store" HorizontalAlignment="Center" Width="150" Height="150" Margin="20,0,0,0" VerticalAlignment="Center"  Tapped="store_Tapped" Source="images/new icon/BSE-book-icon-store.png"/>
                <Image x:Name="bukukoleksi" HorizontalAlignment="Center" Width="150" Height="150" Margin="20,0,0,0" VerticalAlignment="Center" Tapped="koleksi_Tapped" Source="images/new icon/bse-icon300-w8-KOLEKSI.png"/>

<callisto:CustomDialog x:FieldModifier="public" x:Name="LoginDialog" 
                       Title="Login"
                       Background="#FFFCDAA2" BackButtonVisibility="Collapsed" Grid.Row="0" Grid.RowSpan="2">
            <StackPanel x:Name="loginBox">
                <TextBlock x:Name="spacerLogin" VerticalAlignment="Top" Style="{StaticResource TitleTextBlockStyle}" Width="300" Height="50" Text=""/>
                <Grid x:Name="loginEnter">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock x:Name="FailedMessage" FontSize="17" Text="Login failed!" Foreground="Red" Visibility="Collapsed" Grid.Row="0" Grid.ColumnSpan="2"/>
                    <TextBlock x:Name="email" Text="Email:" Grid.Column="0" Grid.Row="1" Margin="0,10,0,0" FontSize="18" Height="40" VerticalAlignment="Center" Foreground="#FFCA6402"/>
                    <TextBox x:Name="emailBox" PlaceholderText="Email" FontSize="17" Grid.Column="1" Grid.Row="1" Margin="10,10,0,0" Height="40" VerticalAlignment="Top"/>
                    <TextBlock x:Name="password" Text="Password:" Grid.Column="0" Grid.Row="2" FontSize="18" Height="40" Margin="0,10,0,0" VerticalAlignment="Center" Foreground="#FFCA6402"/>
                    <PasswordBox x:Name="passwordBox" Grid.Column="1" Grid.Row="2" PlaceholderText="Password" FontSize="18" Height="40" Margin="10,10,0,0"/>
                    <StackPanel Grid.Row="3" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center">
                        <Button x:Name="loginBtn" Background="#FFCA6402" Content="Login" Margin="0,20,0,0" FontWeight="SemiBold" Click="loginBtn_Click" BorderBrush="Black" BorderThickness="1"/>
                        <Button x:Name="cancelLoginBtn" Background="#FFCA6402" Content="Batal" Margin="20,20,0,0" FontWeight="SemiBold" Click="cancelLoginBtn_Click" BorderBrush="Black" BorderThickness="1"/>
                    </StackPanel>
                    <ProgressRing x:Name="loadingLogin" Grid.RowSpan="4" Grid.ColumnSpan="2" Width="50" Height="50" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#FFCA6402" IsActive="False"/>
                </Grid>

1 个答案:

答案 0 :(得分:0)

由于您已经拥有导航标记,因此在登录失败时也可以将它们设置为false。在这种情况下,当登录失败时,它将无法导航。例如:

 //Your code
  catch (HttpRequestException ex)
  {
      //ConnectionException();
      loadingLogin.IsActive = false;
  }
  //Add following code
  if (loadingLogin.IsActive == false)
  {
      isstoreTapped = false;
      iskoleksiTapped = false;
  }

将此代码块添加到ProcessLogin()方法的最后一个。