예제 #1
0
        public void Login(string email, string password)
        {
            HttpWebResponse    response;
            SessionRequestData session = new SessionRequestData();

            session.Email    = email;
            session.Password = password;


            HttpWebRequest request = GetServiceRequest("Sessions", "POST");
            string         body    = Serialize(session);

            request.ContentLength = body.Length;
            SetBody(ref request, body);

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException ex)
            {
                throw ex;
            }



            _session = ((SessionResponseData)Deserialize(response.GetResponseStream(), typeof(SessionResponseData))).Session;
        }
예제 #2
0
        public SessionResponseData LogIn(SessionRequestData sessionData)
        {
            SqlCommand          sqlCommand;
            SessionResponseData returnsessionData = null;
            int session;

            try
            {
                using (SqlConnection conn = new SqlConnection(AppSettings.GetConnectionString("Easynet.Edge.Core.Data.DataManager.Connection", "String")))
                {
                    Encryptor encryptor = new Encryptor(KeyEncrypt);
                    sqlCommand            = DataManager.CreateCommand("User_Login(@OperationType:Int,@Email:NVarchar,@Password:NVarchar,@UserID:Int,@SessionID:Int)", CommandType.StoredProcedure);
                    sqlCommand.Connection = conn;
                    conn.Open();

                    sqlCommand.Parameters["@OperationType"].Value = sessionData.OperationType;
                    if (sessionData.OperationType == OperationTypeEnum.New)
                    {
                        sqlCommand.Parameters["@Email"].Value    = sessionData.Email;
                        sqlCommand.Parameters["@Password"].Value = sessionData.Password;
                    }
                    else
                    {
                        sqlCommand.Parameters["@UserID"].Value = sessionData.UserID;

                        try
                        {
                            sqlCommand.Parameters["@SessionID"].Value = encryptor.Decrypt(sessionData.Session);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Invalid Session,session could no be parse!");
                        }
                    }
                    SqlDataReader sqlReader = sqlCommand.ExecuteReader();
                    if (sqlReader.Read())
                    {
                        session = Convert.ToInt32(sqlReader[0]);
                        if (session > 0)
                        {
                            returnsessionData         = new SessionResponseData();
                            returnsessionData.UserID  = sqlReader.GetInt32(1);
                            returnsessionData.Session = encryptor.Encrypt(session.ToString());
                        }
                    }
                }
                if (returnsessionData == null)
                {
                    throw new Exception("User Name/Password is wrong!");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(returnsessionData);
        }
        public SessionResponseData LogIn(SessionRequestData sessionData)
        {
            SqlCommand          sqlCommand;
            SessionResponseData returnsessionData = null;
            int session;

            try
            {
                using (DataManager.Current.OpenConnection())
                {
                    Encryptor encryptor = new Encryptor(KeyEncrypt);
                    sqlCommand = DataManager.CreateCommand("User_Login(@OperationType:Int,@Email:NVarchar,@Password:NVarchar,@UserID:Int,@SessionID:Int)", CommandType.StoredProcedure);


                    sqlCommand.Parameters["@OperationType"].Value = sessionData.OperationType;
                    if (sessionData.OperationType == OperationTypeEnum.New)
                    {
                        sqlCommand.Parameters["@Email"].Value    = sessionData.Email;
                        sqlCommand.Parameters["@Password"].Value = sessionData.Password;
                    }
                    else
                    {
                        sqlCommand.Parameters["@UserID"].Value = sessionData.UserID;

                        try
                        {
                            sqlCommand.Parameters["@SessionID"].Value = encryptor.Decrypt(sessionData.Session);
                        }
                        catch (Exception ex)
                        {
                            ErrorMessageInterceptor.ThrowError(HttpStatusCode.Forbidden, "Invalid Session,session could no be parse!");
                        }
                    }
                    SqlDataReader sqlReader = sqlCommand.ExecuteReader();
                    if (sqlReader.Read())
                    {
                        session = Convert.ToInt32(sqlReader[0]);
                        if (session > 0)
                        {
                            returnsessionData         = new SessionResponseData();
                            returnsessionData.UserID  = sqlReader.GetInt32(1);
                            returnsessionData.Session = encryptor.Encrypt(session.ToString());
                        }
                    }
                }
                if (returnsessionData == null)
                {
                    ErrorMessageInterceptor.ThrowError(HttpStatusCode.Forbidden, "User Name/Password is wrong!");
                }
            }
            catch (Exception ex)
            {
                ErrorMessageInterceptor.ThrowError(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(returnsessionData);
        }
예제 #4
0
        //public SessionResponseData LogIn(SessionRequestData sessionData)
        public ExtendedSessionResponseData GetLoginInfo(string email = "", string password = "",
                                                        int userId   = 0, string sessionId = "",
                                                        OperationTypeEnum operationType = OperationTypeEnum.New,
                                                        ApplicationType applicationType = ApplicationType.Mobile)
        {
            // no permission validation if configured
            if (AppSettings.Get("MobileApi", "ValidateSession", false) == "false")
            {
                return new ExtendedSessionResponseData {
                           UserID = 105, Session = "aaa"
                }
            }
            ;

            var sessionData = new SessionRequestData
            {
                Email           = email,
                Password        = password,
                UserID          = userId,
                Session         = sessionId,
                OperationType   = operationType,
                ApplicationType = applicationType
            };

            var handler = new CoreHandler();

            try
            {
                var response = handler.LogIn(sessionData);

                Log.Write("Mobile API", String.Format("User {0} logged in to Mobile Application", response.UserID), LogMessageType.Debug);
                return(new ExtendedSessionResponseData {
                    UserID = response.UserID, Session = response.Session
                });
            }
            catch (Exception ex)
            {
                Log.Write("Mobile API", String.Format("Login failed for user email '{0}', ex: {1}", email, ex.Message), LogMessageType.Error);
                return(new ExtendedSessionResponseData
                {
                    HasError = true,
                    ErrorMsg = ex.Message,
                    DisplayError = (ex is MobileApiException) ? (ex as MobileApiException).DisplayMessage : null
                });
            }
        }
    }