Ejemplo n.º 1
0
 public JsonResult AuthenticateUser(string userName, string password, string deviceId)
 {
     try
     {
         var authenticated = Membership.ValidateUser(userName, password);
         if (authenticated)
         {
             var sessionGuid = Guid.NewGuid();
             var session     = new Session()
             {
                 DeviceId    = deviceId,
                 SessionGuid = sessionGuid,
                 UserName    = userName,
                 OpenedOn    = DateTime.Now,
                 IsValid     = true,
                 ClosedOn    = DateTime.Now.AddYears(1)
             };
             DbHelpers.AddSession(session);
             var response = new AuthenticationToken
             {
                 IsAuthenticated = authenticated,
                 Message         = "Success",
                 Role            = Roles.GetRolesForUser(userName).Equals("Administrator")
                     ? SmartVitals.Services.Enums.Roles.Administrator.ToString()
                     : SmartVitals.Services.Enums.Roles.User.ToString(),
                 Profile   = UserInfo.GetFromProfile(WebProfile.GetProfile(userName, authenticated)),
                 SessionId = authenticated ? sessionGuid : new Guid()
             };
             return(Json(
                        new JsonResponse <AuthenticationToken> {
                 Response = response, Success = true
             },
                        JsonRequestBehavior.AllowGet
                        ));
         }
         return(Json(
                    new JsonResponse <AuthenticationToken> {
             Response = null, Success = false, Message = "Invalid username or password"
         },
                    JsonRequestBehavior.AllowGet
                    ));
     }
     catch (Exception)
     {
         return(Json(
                    new JsonResponse <AuthenticationToken> {
             Response = null, Success = false, Message = "An error occured while processing your request."
         },
                    JsonRequestBehavior.AllowGet
                    ));
     }
 }
Ejemplo n.º 2
0
        public static void Save(UserInfo profile)
        {
            WebProfile p = WebProfile.GetProfile(profile.UserName);

            p.Age           = profile.Age;
            p.Email         = profile.Email;
            p.Height.Feet   = profile.Height.Feet;
            p.Height.Inches = profile.Height.Inches;
            p.Name          = profile.Name;
            p.Phone         = profile.Phone;
            p.Sex           = profile.Sex;
            p.Preferences   = profile.Preferences;
            p.Weight        = profile.Weight;
            p.Save();
        }
Ejemplo n.º 3
0
 public JsonResult GetAuthenticationToken(string SessionGuid)
 {
     try
     {
         var selectedSession = DbHelpers.GetSessionByGuid(SessionGuid);
         if (selectedSession != null)
         {
             var response = new AuthenticationToken
             {
                 IsAuthenticated = selectedSession.IsValid,
                 Message         = "Success",
                 Role            = Roles.GetRolesForUser(selectedSession.UserName).Equals("Administrator")
                 ? SmartVitals.Services.Enums.Roles.Administrator.ToString()
                 : SmartVitals.Services.Enums.Roles.User.ToString(),
                 Profile   = UserInfo.GetFromProfile(WebProfile.GetProfile(selectedSession.UserName, selectedSession.IsValid)),
                 SessionId = selectedSession.IsValid ? new Guid(SessionGuid) : new Guid()
             };
             return(Json(
                        new JsonResponse <AuthenticationToken> {
                 Response = response, Success = true
             },
                        JsonRequestBehavior.AllowGet
                        ));
         }
         return(Json(
                    new JsonResponse <AuthenticationToken> {
             Response = null, Success = true, Message = "Expired or invalid session."
         },
                    JsonRequestBehavior.AllowGet
                    ));
     }
     catch (Exception)
     {
         return(Json(
                    new JsonResponse <AuthenticationToken> {
             Response = null, Success = false, Message = "An error occured while processing your request."
         },
                    JsonRequestBehavior.AllowGet
                    ));
     }
 }
Ejemplo n.º 4
0
        public static UserInfo Profile(this System.Security.Principal.IIdentity identity)
        {
            var profile = WebProfile.GetProfile(identity.Name);

            return(UserInfo.GetFromProfile(profile));
        }