public void ChangePasswordByClass(DoctorLogin logindetails) { if (CheckUserName(logindetails.DUserName)) { doctorlogin.Collection.Update( Query.EQ("DUserName", logindetails.DUserName), Update.Set("Password", logindetails.Password)); } }
public DoctorLogin GetLoggedInDoctor(string guid) { DoctorLogin doctorLogin = null; using (SqlConnection conn = new SqlConnection(Environment.GetEnvironmentVariable("sqldb_connection"))) { string sqlQuery = "SELECT d.*, a.first_name, a.last_name, r.role_name " + "FROM Doctor AS d " + "INNER JOIN Account AS a ON a.id = d.account_id " + "INNER JOIN Role AS r ON r.id = a.role " + "WHERE d.guid = @GUID"; SqlCommand cmd = new SqlCommand(sqlQuery, conn); cmd.Parameters.Add("@GUID", SqlDbType.NVarChar).Value = guid; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { doctorLogin = new DoctorLogin { Doctor = new DoctorModel { FirstName = reader["first_name"].ToString(), LastName = reader["last_name"].ToString(), DoctorId = (int)reader["id"], Location = reader["location"].ToString() }, Account = new AccountModel { AccountId = (int)reader["account_id"], Role = reader["role_name"].ToString() }, Auth = new AuthLogin { Guid = reader["guid"].ToString(), } }; } conn.Close(); } return(doctorLogin.Doctor.DoctorId != 0 ? doctorLogin : null); }
public DoctorLogin RegisterDoctor(DoctorLogin doctorLogin) { IAccountRepository accountRepository = DIContainer.Instance.GetService <IAccountRepository>(); // Return null when GUID already exists in DB if (CheckIfExists(doctorLogin.Auth.Guid)) { return(null); } // Register First a new account, if there is an error the AccountId will be 0 doctorLogin.Account.AccountId = accountRepository.RegisterAccount(doctorLogin.Doctor.FirstName, doctorLogin.Doctor.LastName, (int)Role.Doctor); if (doctorLogin.Account.AccountId == 0) { return(null); } string sqlQuery = "INSERT INTO Doctor(account_id, guid, location) " + "OUTPUT Inserted.id " + "VALUES(@ACCOUNTID, @GUID, @LOCATION) "; using (SqlConnection sqlConn = new SqlConnection(Environment.GetEnvironmentVariable("sqldb_connection"))) { SqlCommand sqlCmd = new SqlCommand(sqlQuery, sqlConn); sqlCmd.Parameters.Add("@ACCOUNTID", SqlDbType.Int).Value = doctorLogin.Account.AccountId; sqlCmd.Parameters.Add("@LOCATION", SqlDbType.NVarChar).Value = doctorLogin.Doctor.Location; sqlCmd.Parameters.Add("@GUID", SqlDbType.NVarChar).Value = doctorLogin.Auth.Guid; try { sqlConn.Open(); int result = (int)sqlCmd.ExecuteScalar(); if (result == 0) { return(null); } doctorLogin.Doctor.DoctorId = result; } catch { return(null); } return(doctorLogin); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = (Routes.APIVersion + Routes.Doctor))] HttpRequest req, ILogger log) { AuthLogin authLogin = await DIContainer.Instance.GetService <IAuthorization>().LoginAuthAsync(req); if (authLogin == null) { return(new BadRequestObjectResult(Messages.AuthNoAcces)); } DoctorLogin newDoctor; try { StreamReader streamReader = new StreamReader(req.Body); var content = await streamReader.ReadToEndAsync(); streamReader.Dispose(); // Parse Patient Info JObject jsonParsed = JObject.Parse(content); newDoctor = new DoctorLogin { Doctor = new DoctorModel { FirstName = jsonParsed["firstName"].ToString(), LastName = jsonParsed["lastName"].ToString(), Location = jsonParsed["location"].ToString() }, Auth = new AuthLogin { Guid = authLogin.Guid } }; } catch { return(new BadRequestResult()); } IDoctorRepository doctorRepository = DIContainer.Instance.GetService <IDoctorRepository>(); newDoctor = doctorRepository.RegisterDoctor(newDoctor); newDoctor.Auth = authLogin; return(newDoctor != null ? (ActionResult) new OkObjectResult(newDoctor) : new BadRequestResult()); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = (Routes.APIVersion + Routes.LoginDoctor))] HttpRequest req, ILogger log) { AuthLogin authLogin = await DIContainer.Instance.GetService <IAuthorization>().LoginAuthAsync(req); if (authLogin == null) { return(new BadRequestObjectResult(Messages.AuthNoAcces)); } IDoctorRepository doctorRepository = DIContainer.Instance.GetService <IDoctorRepository>(); DoctorLogin doctorLogin = doctorRepository.GetLoggedInDoctor(authLogin.Guid); return(doctorLogin != null ? (ActionResult) new OkObjectResult(doctorLogin) : new BadRequestResult()); }
public bool CheckLoginWthClass(DoctorLogin loginattempt) { if (CheckUserName(loginattempt.DUserName)) { var data = doctorlogin.Collection.Find(Query.EQ("DUserName", loginattempt.DUserName)).Single(); if (data.Password.Equals(loginattempt.Password)) { return true; } else { //Incorrect Password return false; } } else { // No UserName return false; } }
public DoctorLogin Post([FromBody] TblDoctor drLogin) { TblDoctor doctor = msc.TblDoctor.FromSql("doctorauthentication '" + drLogin.DrUserId + "','" + drLogin.DrPassword + "'").SingleOrDefault(); if (doctor != null) { DoctorLogin drdetailsFetch = new DoctorLogin(); drdetailsFetch.DrUserId = doctor.DrUserId; drdetailsFetch.DrFirstName = doctor.DrFirstName; drdetailsFetch.DrLastName = doctor.DrLastName; drdetailsFetch.SNo = doctor.SNo; drdetailsFetch.DrMdMedicareServiceId = doctor.DrMdMedicareServiceId; return(drdetailsFetch); } else { DoctorLogin drdetailsFetch = new DoctorLogin(); drdetailsFetch = null; return(drdetailsFetch); } }
public void Edit(DoctorLogin logindetails) { //broken if (CheckUserName(logindetails.DUserName)) { /*doctorlogin.Collection.Update(Query.EQ("DUserName", logindetails.DUserName), Update.Set("Password", logindetails.Password) .Set("IsConfirmed", logindetails.IsConfirmed) .Set("ConfirmationToken",logindetails.ConfirmationToken) .Set("LastPasswordFailureDate", logindetails.LastPasswordFailureDate) .Set("PasswordFailuresSinceLastSuccess", logindetails.PasswordFailuresSinceLastSuccess) .Set("PasswordChangedDate", logindetails.PasswordChangedDate) .Set("PasswordVerificationToken", logindetails.PasswordVerificationToken) .Set("PasswordVerificationTokenExpirationDate", logindetails.PasswordVerificationTokenExpirationDate) .Set("LastLoginDate", logindetails.LastLoginDate));*/ doctorlogin.Collection.Save(logindetails); //Update(Query.EQ("DUserName", logindetails.DUserName), } }
public void CreateLogin(DoctorLogin logins) { if (!CheckUserName(logins.DUserName)) { doctorlogin.Collection.Save(logins); } }
public void CreateFullAccount(DoctorLogin logins, DoctorDetails details) { if ((!CheckUserName(logins.DUserName)) && (logins.DUserName.Equals(details.DUserName))) { doctorlogin.Collection.Save(logins); DatabaseDDetails savedetails = new DatabaseDDetails(ConnectString); savedetails.Create(details); } else { //Error } }