SECO DMS

SECO DMS

  • NA
  • 24
  • 762

Registration Implementation asp.net Web Form

Nov 15 2020 10:30 AM
this is my class code
  1. namespace SECODMS.Model {    
  2. public class ApplicationUser {   
  3.     public string UserName { get ; set; }    
  4.     public string FirstName{ getset; }    
  5.     public string LastName { getset; }    
  6.     public string Email { getset; }    
  7.     public string AvatarUrl { getset; }    
  8. }    
  9.   
  10. public static class AuthHelper {    
  11.     public static bool SignIn(string userName, string password) {    
  12.         HttpContext.Current.Session["User"] = CreateDefualtUser();    
  13.        // Mock user data     
  14.         return true;    
  15.     }    
  16.     public static void SignOut() {    
  17.         HttpContext.Current.Session["User"] = null;    
  18.     }    
  19.     public static bool IsAuthenticated() {    
  20.         return GetLoggedInUserInfo() != null;    
  21.     }     
  22.     public static ApplicationUser GetLoggedInUserInfo()     
  23.     {    
  24.         return HttpContext.Current.Session["User"as ApplicationUser;    
  25.     }    
  26.     private static ApplicationUser CreateDefualtUser() {    
  27.         return new ApplicationUser {    
  28.                
  29.             UserName ="vvnbnbnb",    
  30.             FirstName = "Julia",    
  31.             LastName = "Bell",    
  32.             Email = "[email protected]",    
  33.             AvatarUrl = "~/Content/Photo/Julia_Bell.jpg"    
  34.         };    
  35.     }             
  36. }  
  1. using System;  
  2. using DevExpress.Web;  
  3. using SECODMS.Model;  
  4. using System.Configuration;  
  5. using System.Data;  
  6. using System.Data.SqlClient;  
  7.   
  8. namespace SECODMS {  
  9.   public partial class SignInModule: System.Web.UI.Page  
  10.   
  11.   {  
  12.     protected void Page_Load(object sender, EventArgs e)  
  13.     {  
  14.     }  
  15.     protected void SignInButton_Click(object sender, EventArgs e) {  
  16.   
  17.       FormLayout.FindItemOrGroupByName("GeneralError").Visible = false;  
  18.   
  19.       if (ASPxEdit.ValidateEditorsInContainer(this)) {  
  20.         // DXCOMMENT: You Authentication logic  //     
  21.         string mainconn = ConfigurationManager.ConnectionStrings["SECODMSConnectionString"].ConnectionString;  
  22.         SqlConnection sqlconn = new SqlConnection(mainconn);  
  23.         string sqlquery = "Select * from Users where Username=@Username and Password=@Password";  
  24.         SqlCommand sqlcomm = new SqlCommand(sqlquery, sqlconn);  
  25.         sqlconn.Open();  
  26.         sqlcomm.Parameters.AddWithValue("@Username", UserNameTextBox.Text);  
  27.         sqlcomm.Parameters.AddWithValue("@Password", PasswordButtonEdit.Text);  
  28.         SqlDataAdapter sda = new SqlDataAdapter(sqlcomm);  
  29.         DataTable dt = new DataTable();  
  30.         sda.Fill(dt);  
  31.         sqlcomm.ExecuteNonQuery();  
  32.         if (dt.Rows.Count > 0) {  
  33.           Session["user"] = UserNameTextBox;  
  34.           Response.Redirect("~/Default.aspx");  
  35.         }  
  36.         else {}  
  37.         if (!AuthHelper.SignIn(UserNameTextBox.Text, PasswordButtonEdit.Text)) {  
  38.           GeneralErrorDiv.InnerText = "Invalid login attempt.";  
  39.           FormLayout.FindItemOrGroupByName("GeneralError").Visible = true;  
  40.   
  41.         }  
  42.         else Response.Redirect("~/Default.aspx");  
  43.       }  
  44.     }  
  45.   }  
  46. }  
and this my sign in code kindly advise me what's wrong I am not able to, getting the value from the session and then casting as ApplicationUser.

Answers (3)