我有一个使用Net Core作为后端对Azure AD进行身份验证的Vue应用程序,我创建了一个控制器来提供一些基本的用户信息:
List<Uservaluesfull> values = new List<Uservaluesfull>();
using (SqlConnection myConnection = new
SqlConnection(PathwayConnString))
{
SqlCommand myCommand = new SqlCommand("usp_GetUserInfo",
myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter SIDParameter = myCommand.Parameters.Add("SID",
SqlDbType.NVarChar, 100);
SIDParameter.Value = SID;
myConnection.Open();
using (SqlDataReader oReader = myCommand.ExecuteReader())
{
while (oReader.Read())
{
Uservaluesfull s = new Uservaluesfull();
s.SID = SafeGetString(oReader, "SID");
s.FirstName = SafeGetString(oReader, "FirstName");
s.LastName = SafeGetString(oReader, "LastName");
s.FullName = SafeGetString(oReader, "FullName");
s.WorkOffice = SafeGetString(oReader, "WorkOffice");
s.Department = SafeGetString(oReader, "Department");
s.WorkPhoneNumber = SafeGetString(oReader,
"WorkPhoneNumber");
s.WorkEmail = SafeGetString(oReader, "WorkEmail");
values.Add(s);
}
myConnection.Close();
}
}
return values;
}
我称之为:
created() {
axios.get(`/api/UserValues`)
.then(response => {
// JSON responses are automatically parsed.
this.userValues = response.data
})
.catch(e => {
this.errors.push(e)
})
}
并提供我用于将用户信息放入应用程序中的基本信息,
我的问题是:
如果我将组添加到userValues控制器,则如何使用此信息创建服务,从而限制用户从一个路由转到另一条路由,因为他们不属于特定组:
示例:
如果Uservalues.Groups = GymAdmin用户有权访问所有组件,则该用户将被重定向到首页。
否则,用户将被重定向到一个特定页面,并且无权查看或移动到其他任何路线。
路线:
import Notifications from 'components/notifications'
import Students from 'components/students'
import HomePage from 'components/home-page'
import Athletes from 'components/athletes'
export const routes = [
{ name: 'home', path: '/', component: HomePage, display: 'Home', icon:
'home' },
{ name: 'students', path: '/students', component: Students, display:
'Students', icon: 'person' },
{ name: 'athletes', path: '/athletes', component: Athletes, display:
'Athletes', icon: 'fitness_center' },
//{ name: 'counter', path: '/counter', component: CounterExample, display:
'Reports', icon: 'bar_chart' },
{ name: 'notifications', path: '/notifications', component: Notifications,
display: 'Notifications', icon: 'list' }