/// <summary>Compare object with another</summary> /// <param name="other">Object to compare</param> /// <returns>Indicates if objects are equals</returns> public bool Equals(LogOnObject other) { if (other == null) { return(false); } if (this.Result != other.Result) { return(false); } return(this.Result == other.Result); }
/// <summary>Log on application</summary> /// <param name="email">User email</param> /// <param name="password">User password</param> /// <param name="clientAddress">IP address from log on action</param> /// <returns>Result of action</returns> public static ActionResult GetApplicationAccess(string email, string password, string clientAddress) { HttpContext.Current.Session["Companies"] = null; if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { return(ActionResult.NoAction); } var res = ActionResult.NoAction; var result = new LogOnObject { Id = -1, UserName = string.Empty, Result = LogOnResult.NoUser }; var companiesId = new List <string>(); using (var cmd = new SqlCommand("GetLogin")) { cmd.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString); try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(DataParameter.Input("@Login", email)); cmd.Parameters.Add(DataParameter.Input("@Password", password)); cmd.Connection.Open(); using (var rdr = cmd.ExecuteReader()) { bool multiCompany = false; if (rdr.HasRows) { while (rdr.Read()) { companiesId.Add(rdr.GetInt32(ColumnsGetLogin.CompanyId).ToString() + '|' + rdr.GetInt32(ColumnsGetLogin.Id).ToString()); result.Id = rdr.GetInt32(ColumnsGetLogin.Id); result.Result = IntegerToLogOnResult(rdr.GetInt32(ColumnsGetLogin.Status)); result.UserName = email; result.CompanyId = rdr.GetInt32(ColumnsGetLogin.CompanyId); result.MustResetPassword = rdr.GetBoolean(ColumnsGetLogin.MustResetPassword); result.Agreement = rdr.GetBoolean(ColumnsGetLogin.Agreement); if (result.Result == LogOnResult.Fail) { LogOnFailed(result.Id); } else { var user = new ApplicationUser { Id = result.Id, UserName = rdr.GetString(ColumnsGetLogin.UserName), Language = rdr.GetString(ColumnsGetLogin.Language), Status = result.Result }; user.ObtainGrants(); HttpContext.Current.Session["User"] = user; } result.MultipleCompany = multiCompany; multiCompany = true; } } else { result.Result = LogOnResult.NoUser; res.ReturnValue = result; res.SetFail("NO USER"); return(res); } } } catch (SqlException ex) { result.Result = LogOnResult.Fail; result.Id = -1; result.UserName = ex.Message; } catch (FormatException ex) { result.Result = LogOnResult.Fail; result.Id = -1; result.UserName = ex.Message; } catch (NullReferenceException ex) { result.Result = LogOnResult.Fail; result.Id = -1; result.UserName = ex.Message; } finally { if (cmd.Connection.State != ConnectionState.Closed) { cmd.Connection.Close(); } } } bool resultOk = result.Result == LogOnResult.Ok || result.Result == LogOnResult.Admin || result.Result == LogOnResult.Administrative; if (string.IsNullOrEmpty(clientAddress)) { clientAddress = "no-ip"; } HttpContext.Current.Session["Companies"] = companiesId; InsertLog(email, clientAddress, resultOk ? 1 : 2, result.Id, string.Empty, result.CompanyId); res.SetSuccess(result); return(res); }