Example #1
0
        public bool Authenticate(string Username, string Password)
        {
            //Create an authentication object
            user_auth user = new user_auth();

            //Set the credentials
            user.user_name = Username;
            user.password  = this.computeMD5String(Password);

            //Try to authenticate
            set_entry_result authentication_result = this.sugarClient.login(user, "");

            //Check for errors
            if (Convert.ToInt32(authentication_result.error.number) != 0)
            {
                //An error occured
                this.error = String.Concat(authentication_result.error.name, ": ",
                                           authentication_result.error.description);

                //Clear the existing sessionId
                this.sessionId = String.Empty;
            }
            else
            {
                //Set the sessionId
                this.sessionId = authentication_result.id;

                //Clear the existing error
                this.error = String.Empty;
            }

            //Return the boolean
            return(this.sessionId != String.Empty);
        }
Example #2
0
    public string SetEntry(SugarEntry entry)
    {
        var valueArray = new name_value[entry.Count];
        int i          = 0;

        foreach (var sugarEntry in entry)
        {
            valueArray[i]       = new name_value();
            valueArray[i].name  = sugarEntry.Key;
            valueArray[i].value = sugarEntry.Value;
            i++;
        }
        set_entry_result result = _sugarsoap.set_entry(_session, entry.Module, valueArray);

        VerifySugarResult.Verify(result.error);
        return(result.id);
    }
Example #3
0
        public set_entry_result set_note_attachment(string session, note_attachment note)
        {
            Guid   gUSER_ID        = GetSessionUserID(session);
            Guid   gNOTE_ID        = Sql.ToGuid(note.id);
            string sFILENAME       = Path.GetFileName (note.filename);
            string sFILE_EXT       = Path.GetExtension(sFILENAME);
            string sFILE_MIME_TYPE = "application/octet-stream";

            int nACLACCESS = Security.GetUserAccess("Notes", "edit");
            if ( nACLACCESS < 0 )
            {
                L10N L10n = new L10N("en-US");
                throw(new Exception(L10n.Term("ACL.LBL_INSUFFICIENT_ACCESS")));
            }

            set_entry_result result = new set_entry_result();
            byte[] byData = Convert.FromBase64String(note.file);
            // 02/20/2006 Paul.  Try and reduce the memory requirements by releasing the original data as soon as possible.
            note.file = null;
            using ( MemoryStream stm = new System.IO.MemoryStream(byData) )
            {
                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                using ( IDbConnection con = dbf.CreateConnection() )
                {
                    con.Open();
                    Guid gASSIGNED_USER_ID = Guid.Empty;

                    /*
                    // 09/01/2006 Paul.  Notes do not have an ASSIGNED_USER_ID.
                    string sSQL = String.Empty;
                    sSQL = "select *           " + ControlChars.CrLf
                         + "  from vwNOTES_Edit" + ControlChars.CrLf
                         + " where ID = @ID    " + ControlChars.CrLf;
                    using ( IDbCommand cmd = con.CreateCommand() )
                    {
                        cmd.CommandText = sSQL;
                        Sql.AddParameter(cmd, "@ID", gNOTE_ID);
                        using ( IDataReader rdr = cmd.ExecuteReader() )
                        {
                            if ( rdr.Read() )
                            {
                                gASSIGNED_USER_ID = Sql.ToGuid(rdr["ASSIGNED_USER_ID"]);
                            }
                        }
                    }
                    */
                    if ( nACLACCESS != ACL_ACCESS.OWNER || (nACLACCESS == ACL_ACCESS.OWNER  && gASSIGNED_USER_ID == gUSER_ID) )
                    {
                        using ( IDbTransaction trn = con.BeginTransaction() )
                        {
                            try
                            {
                                Guid gAttachmentID = Guid.Empty;
                                SqlProcs.spNOTE_ATTACHMENTS_Insert(ref gAttachmentID, gNOTE_ID, note.filename, sFILENAME, sFILE_EXT, sFILE_MIME_TYPE, trn);
                                SplendidCRM.Notes.EditView.LoadFile(gAttachmentID, stm, trn);
                                trn.Commit();
                            }
                            catch(Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                throw ( new Exception(ex.Message) );
                            }
                        }
                    }
                }
            }
            byData = null;
            return result;
        }
Example #4
0
        public set_entry_result set_entry(string session, string module_name, name_value[] name_value_list)
        {
            Guid gUSER_ID  = GetSessionUserID(session);
            Guid gTIMEZONE = Sql.ToGuid(HttpContext.Current.Cache.Get("soap.user.timezone." + gUSER_ID.ToString()));
            TimeZone T10n = TimeZone.CreateTimeZone(gTIMEZONE);

            string sTABLE_NAME = VerifyModuleName(module_name);
            int nACLACCESS = Security.GetUserAccess(module_name, "edit");
            if ( nACLACCESS < 0 )
            {
                L10N L10n = new L10N("en-US");
                throw(new Exception(L10n.Term("ACL.LBL_INSUFFICIENT_ACCESS")));
            }

            set_entry_result results = new set_entry_result();

            DbProviderFactory dbf = DbProviderFactories.GetFactory();
            using ( IDbConnection con = dbf.CreateConnection() )
            {
                con.Open();
                // 02/21/2006 Paul.  Delete operations come in as set_entry with deleted = 1.
                if ( DeleteEntry(name_value_list) )
                {
                    IDbCommand cmdDelete = SqlProcs.Factory(con, "sp" + sTABLE_NAME + "_Delete");
                    // 10/10/2006 Paul.  Use IDbDataParameter to be consistent.
                    foreach(IDbDataParameter par in cmdDelete.Parameters)
                    {
                        par.Value = DBNull.Value;
                    }
                    Sql.SetParameter(cmdDelete, "@MODIFIED_USER_ID", gUSER_ID.ToString());
                    Guid gID = FindID(name_value_list);
                    if ( gID != Guid.Empty )
                    {
                        Sql.SetParameter(cmdDelete, "@ID", gID.ToString());
                        cmdDelete.ExecuteNonQuery();
                    }
                }
                else
                {
                    IDbCommand cmdUpdate = SqlProcs.Factory(con, "sp" + sTABLE_NAME + "_Update");
                    IDbDataParameter parID = Sql.FindParameter(cmdUpdate, "@ID");
                    // 10/10/2006 Paul.  Use IDbDataParameter to be consistent.
                    foreach(IDbDataParameter par in cmdUpdate.Parameters)
                    {
                        par.Value = DBNull.Value;
                    }
                    // 08/31/2006 Paul.  We need to initialize the values of any fields not provided.
                    // The stored procedure always updates all fields, so we need to make sure not to clear fields that are not provided.
                    // This problem was first noticed when the Outlook Plug-in kept clearing the ASSIGNED_USER_ID field.
                    Guid gID = FindID(name_value_list);
                    if ( gID != Guid.Empty )
                    {
                        // 08/31/2006 Paul.  If the ID is not found, then this must be a new
                        InitializeParameters(con, sTABLE_NAME, gID, cmdUpdate);
                    }
                    Sql.SetParameter(cmdUpdate, "@MODIFIED_USER_ID", gUSER_ID.ToString());

                    for ( int j = 0; j < name_value_list.Length; j++ )
                    {
                        // 04/04/2006 Paul.  DATE_START & TIME_START need to be combined into DATE_TIME.
                        if ( name_value_list[j].name.ToUpper() == "TIME_START" )
                        {
                            // 04/04/2006 Paul.  Modules that have a TIME_START field are MEETINGS, CALLS, TASKS, EMAILS, EMAIL_MARKETING, PROJECT_TASK
                            string sDateTime = EntryDateTime(name_value_list, "DATE_START", "TIME_START");
                            if ( sTABLE_NAME == "TASKS" || sTABLE_NAME == "PROJECT_TASK" )
                            {
                                Sql.SetParameter(cmdUpdate, "@DATE_TIME_START", T10n.ToServerTimeFromUniversalTime(sDateTime));
                            }
                            else
                            {
                                Sql.SetParameter(cmdUpdate, "@DATE_TIME", T10n.ToServerTimeFromUniversalTime(sDateTime));
                            }
                        }
                        // 04/04/2006 Paul.  DATE_DUE & TIME_DUE need to be combined into DATE_TIME_DUE.
                        else if ( name_value_list[j].name.ToUpper() == "TIME_DUE" )
                        {
                            // 04/04/2006 Paul.  Modules that have a TIME_DUE field are TASKS, PROJECT_TASK
                            string sDateTime = EntryDateTime(name_value_list, "DATE_DUE", "TIME_DUE");
                            Sql.SetParameter(cmdUpdate, "@DATE_TIME_DUE", T10n.ToServerTimeFromUniversalTime(sDateTime));
                        }
                        else
                        {
                            Sql.SetParameter(cmdUpdate, "@" + name_value_list[j].name, name_value_list[j].value);
                        }
                    }
                    cmdUpdate.ExecuteNonQuery();

                    if ( parID != null )
                    {
                        results.id = Sql.ToString(parID.Value);
                    }
                }
            }
            return results;
        }
Example #5
0
 public set_entry_result login(user_auth user_auth, string application_name)
 {
     // 03/12/2007 Paul.  If we are using NTLM, then the user_name will be blank.
     // This could be one of the reasons why some sessions were dying.
     if ( Security.IsWindowsAuthentication() )
     {
         string[] arrUserName = HttpContext.Current.User.Identity.Name.Split('\\');
         string sUSER_DOMAIN = arrUserName[0];
         user_auth.user_name = arrUserName[1];
     }
     // 12/29/2005 Paul.  create_session returns "Suceess".  We need a separate operation to get the SessionID.
     set_entry_result result = new set_entry_result();
     // 06/04/2007 Paul.  Use new function that returns the Session ID.
     result.id = CreateSession(user_auth.user_name, user_auth.password).ToString();
     //result.id = Sql.ToString(HttpContext.Current.Cache.Get("soap.username.session." + user_auth.user_name.ToLower()));
     return result;
 }
Example #6
0
 public set_entry_result login(user_auth user_auth, string application_name)
 {
     create_session(user_auth.user_name, user_auth.password);
     // 12/29/2005 Paul.  create_session returns "Suceess".  We need a separate operation to get the SessionID.
     set_entry_result result = new set_entry_result();
     result.id = Sql.ToString(HttpContext.Current.Cache.Get("soap.username.session." + user_auth.user_name.ToLower()));
     return result;
 }