Example #1
0
        ///<summary>Creates a username that is not yet in use. Should typically call UserWebs.GetNewPatientPortalCredentials() instead.
        ///If you are not inserting the name into UserWeb immediately then listExcludedNames should persist across multiple calls.</summary>
        public static string CreateUserNameFromPat(Patient pat, UserWebFKeyType fkeyType, List <string> listExcludedNames)
        {
            //No need to check RemotingRole; no call to db.
            string retVal       = "";
            bool   isUserNameOk = false;
            int    i            = 0;

            while (!isUserNameOk)
            {
                retVal = pat.FName + ODRandom.Next(100, 100000);
                if (!UserWebs.UserNameExists(retVal, fkeyType))
                {
                    if (!listExcludedNames.Contains(retVal))
                    {
                        isUserNameOk = true;
                    }
                }
                if (i > 1000)
                {
                    throw new CodeBase.ODException(Lans.g("UserWebs", "Unable to create username for patient."));
                }
                i++;
            }
            return(retVal);
        }
Example #2
0
 public static bool UserNameExists(string userName, UserWebFKeyType fkeyType)
 {
     //No need to check RemotingRole; no call to db.
     if (GetUserNameCount(userName, fkeyType) != 0)
     {
         return(true);
     }
     return(false);
 }
Example #3
0
        public static UserWeb GetByFKeyAndType(long fkey, UserWebFKeyType fkeyType)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <UserWeb>(MethodBase.GetCurrentMethod(), fkey, fkeyType));
            }
            string command = "SELECT * FROM userweb WHERE FKey=" + POut.Long(fkey) + " AND FKeyType=" + POut.Int((int)fkeyType) + " ";

            return(Crud.UserWebCrud.SelectOne(command));
        }
Example #4
0
        public static int GetUserNameCount(string userName, UserWebFKeyType fkeyType)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetInt(MethodBase.GetCurrentMethod(), userName, fkeyType));
            }
            string command = "SELECT COUNT(*) FROM userweb WHERE UserName='******' AND FKeyType=" + POut.Int((int)fkeyType);

            return(PIn.Int(Db.GetCount(command)));
        }
Example #5
0
        ///<summary>Gets all UserWebs from the db for the passed in type.</summary>
        public static List <UserWeb> GetAllByType(UserWebFKeyType fkeyType)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <UserWeb> >(MethodBase.GetCurrentMethod(), fkeyType));
            }
            string command = $"SELECT * FROM userweb WHERE FKeyType={POut.Int((int)fkeyType)}";

            return(Crud.UserWebCrud.SelectMany(command));
        }
Example #6
0
 ///<summary></summary>
 public static long InsertFailed(string userName, UserWebFKeyType type)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         return(Meth.GetLong(MethodBase.GetCurrentMethod(), userName, type));
     }
     return(Crud.LoginAttemptCrud.Insert(new LoginAttempt {
         UserName = userName, LoginType = type
     }));
 }
Example #7
0
        ///<summary>Returns the login attempts for the given user in the last X minutes.</summary>
        public static int CountForUser(string userName, UserWebFKeyType type, int lastXMinutes)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <int>(MethodBase.GetCurrentMethod(), userName, type, lastXMinutes));
            }
            string command = $@"SELECT COUNT(*) FROM loginattempt WHERE UserName='******' AND LoginType={POut.Int((int)type)}
				AND DateTFail >= {DbHelper.DateAddMinute("NOW()",POut.Int(-lastXMinutes))}"                ;

            return(PIn.Int(Db.GetCount(command)));
        }
Example #8
0
        ///<summary>Gets the UserWeb associated to the passed in username.  Must provide the FKeyType.  Returns null if not found.</summary>
        public static UserWeb GetByUserName(string userName, UserWebFKeyType fkeyType)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <UserWeb>(MethodBase.GetCurrentMethod(), userName, fkeyType));
            }
            string command = "SELECT * "
                             + "FROM userweb "
                             + "WHERE UserName='******' "
                             + "AND FKeyType=" + OpenDentBusiness.POut.Int((int)fkeyType) + "";

            return(Crud.UserWebCrud.SelectOne(command));
        }
Example #9
0
        public static bool UserNameExists(string userName, UserWebFKeyType fkeyType)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetBool(MethodBase.GetCurrentMethod(), userName, fkeyType));
            }
            string command = "SELECT COUNT(*) FROM userweb WHERE UserName='******' AND FKeyType=" + POut.Int((int)fkeyType) + " ";
            string count   = Db.GetCount(command);

            if (count != "0")
            {
                return(true);
            }
            return(false);
        }
Example #10
0
        public static UserWeb CreateUserWeb(long fKey, UserWebFKeyType fKeyType, string userName = "", string password = "", bool requireUserNameChange = false,
                                            bool requirePasswordChange = false, string passwordResetCode = "", DateTime dateTimeLastLogin = default(DateTime))
        {
            UserWeb userWeb = new UserWeb()
            {
                IsNew    = true,
                FKey     = fKey,
                FKeyType = fKeyType,
                UserName = userName,
                Password = password,
                RequireUserNameChange = requireUserNameChange,
                RequirePasswordChange = requirePasswordChange,
                PasswordResetCode     = passwordResetCode,
                DateTimeLastLogin     = dateTimeLastLogin,
            };

            UserWebs.Insert(userWeb);
            return(userWeb);
        }
Example #11
0
        ///<summary>Creates a username that is not yet in use.</summary>
        public static string CreateUserNameFromPat(Patient pat, UserWebFKeyType fkeyType)
        {
            //No need to check RemotingRole; no call to db.
            string retVal        = "";
            bool   userNameFound = false;
            Random rand          = new Random();
            int    i             = 0;

            while (!userNameFound)
            {
                retVal = pat.FName + rand.Next(100, 100000);
                if (!UserWebs.UserNameExists(retVal, fkeyType))
                {
                    userNameFound = true;
                }
                if (i > 1000)
                {
                    throw new CodeBase.ODException(Lans.g("UserWebs", "Unable to create username for patient."));
                }
                i++;
            }
            return(retVal);
        }
Example #12
0
        ///<summary>Gets the UserWeb associated to the passed in username and reset code.  Must provide the FKeyType.  Returns null if not found.</summary>
        public static UserWeb GetByUserNameAndResetCode(string userName, string resetCode, UserWebFKeyType fkeyType)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <UserWeb>(MethodBase.GetCurrentMethod(), userName, resetCode, fkeyType));
            }
            string command = "SELECT * "
                             + "FROM userweb "
                             + "WHERE userweb.FKeyType=" + POut.Int((int)UserWebFKeyType.PatientPortal) + " "
                             + "AND userweb.UserName='******' "
                             + "AND userweb.PasswordResetCode='" + POut.String(resetCode) + "' ";

            return(Crud.UserWebCrud.SelectOne(command));
        }