How to return json result for login in 3 cases ?

  • Thread starter Thread starter engahmedbarbary
  • Start date Start date
E

engahmedbarbary

Guest
problem

problem

How to return json result for login in 3 cases ?

i make web API by dot net core and i need to make login function generate json as following ?

Expected Result
Body
{
"username": "",
"password":"",
"browser_info" : {TBD}
"client_ip" : ""
}


Response
if login succeeded:
{
"request_status" : {
"status" : "succeeded",
"code": 0,
"message" : "login succeeded!"
},
access_token : "",
user_data: { UserFullName, LoginTime, Admin },
branches: [
{ BranchCode, BranchName }
]
}


if login failed:
{
request_status : {
"status" : "failed",
"code": 1,
"message" : "login failed, incorrect username or password"
}
}


if password expired:
{
request_status : {
"status" : "failed",
"code": 2,
"message" : "password has expired!"
}
}



----------------------------------



Status Codes:
0 succeeded
1 incorrect username or password
2 password expired




my code as below by using csharp and i using asp.net core 2.2 web api

public string PostUserLogin(string UserId, string Password)
{
DataAccess.CurrentDataBase = DataAccess.Credentials.SecurityDB;
//================
if (!string.IsNullOrEmpty(UserId))
{
DbParameter[] parameters = UserManager.CreateLoginParameters(UserId,Password);
//:: Check For PassWord Validation days
DataTable dt = DataAccess.ExecuteDataTable(SqlFactory.Queries.Userss_ValidatePasswordDays(), parameters);
DataRow PassWordDays;
if (dt.Rows.Count > 0) PassWordDays = dt.Rows[0];
else PassWordDays = null;


if (PassWordDays != null)
{
if (!string.IsNullOrEmpty(PassWordDays["PasswordDate"].ToString()) && !string.IsNullOrEmpty(PassWordDays["PWDays"].ToString()))
{
if (Convert.ToInt32(PassWordDays["PWDays"].ToString()) > 0)
{
if (Convert.ToDateTime(PassWordDays["PasswordDate"].ToString()).AddDays(Convert.ToDouble(PassWordDays["PWDays"].ToString())).ToOADate() < DateTime.Now.ToOADate())
{


}
}
}
}

//==============
bool IsUserValid = UserManager.IsValidUser(UserId, Password);
if (IsUserValid)
{
DataAccess.Credentials.SystemUserID = UserId;
DataTable dtGetBranches = DataAccess.ExecuteDataTable(
SqlFactory.Queries.Users_GetBranches(
DataAccess.Credentials.SystemUserID));
}
else
{
string.Format("Invalid User Name {0} Or Password {1}",UserId,Password);
}

}
}
and i user services
public class AuthunticationService:IAuthunticationsService
{
what i write here
}
public interface IAuthunticationsService
{
//Post User Login

}

Continue reading...
 
Back
Top