我在我的User类中添加了一个类似的字段
public class EmailDAL
{
internal string SMTP = ConfigurationManager.AppSettings["smtpServer"];
internal string MailAddress = ConfigurationManager.AppSettings["smtpUser"];
internal string Pwd = ConfigurationManager.AppSettings["smtpPass"];
internal int Port = Convert.ToInt16(ConfigurationManager.AppSettings["smtpPort"]);
internal bool ssl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
public string SendEmail(string toMail, string mailSubject, string Message)
{
SmtpClient SmtpServer = new SmtpClient(SMTP);
var mail = new MailMessage();
mail.From = new MailAddress(MailAddress);
mail.To.Add(toMail);
mail.Subject = mailSubject;
mail.IsBodyHtml = true;
mail.Body = "<p style='line-height: 30px;'>" + Message + "</p>";
SmtpServer.Port = Port;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(MailAddress, Pwd);
SmtpServer.EnableSsl = ssl;
try
{
SmtpServer.Send(mail);
return "Send Sucessfully";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
}
我需要覆盖
UserInterface-&gt; getRoles()方法并返回我拥有的所有角色。
/**
* @ORM\Column(type="boolean", nullable=false)
*/
protected $isOp;
是Role
,它实现了FOS提供的Entity
。
当我拨打RoleInterface
时,在我的任何模板内部,如果用户的组被标记为is_granted('ROLE_DOUGH')
(isOp字段),我需要立即获得。