public IHttpActionResult Get(string username) { return(Authorized(token => { try { int userid = _userRepository.GetUserIdByUsername(username); MpUser user = _userRepository.GetUserByRecordId(userid); var userRoles = _userRepository.GetUserRoles(userid); MpMyContact contact = _contactRepository.GetContactByUserRecordId(user.UserRecordId); var r = new LoginReturn { userToken = token, userTokenExp = "", refreshToken = "", userId = contact.Contact_ID, username = contact.First_Name, userEmail = contact.Email_Address, roles = userRoles, age = contact.Age, userPhone = contact.Mobile_Phone, canImpersonate = user.CanImpersonate }; return Ok(r); } catch (Exception e) { var apiError = new ApiErrorDto($"{e.Message}"); throw new HttpResponseException(apiError.HttpResponseMessage); } })); }
public IHttpActionResult isAuthenticated() { return(Authorized(token => { try { //var personService = new PersonService(); var person = _personService.GetLoggedInUserProfile(token); if (person == null) { return this.Unauthorized(); } else { var roles = _personService.GetLoggedInUserRoles(token); var user = _userService.GetByAuthenticationToken(token); var l = new LoginReturn(token, person.ContactId, person.FirstName, person.EmailAddress, person.MobilePhone, roles, user.CanImpersonate); return this.Ok(l); } } catch (Exception) { return this.Unauthorized(); } })); }
public IHttpActionResult Post([FromBody] Credentials cred) { try { // try to login var authData = AuthenticationRepository.Authenticate(cred.username, cred.password); var token = authData.AccessToken; var exp = authData.ExpiresIn + ""; var refreshToken = authData.RefreshToken; if (token == "") { return(this.Unauthorized()); } var userRoles = _personService.GetLoggedInUserRoles(token); var user = _userService.GetByAuthenticationToken(token); var p = _personService.GetLoggedInUserProfile(token); var r = new LoginReturn { userToken = token, userTokenExp = exp, refreshToken = refreshToken, userId = p.ContactId, username = p.FirstName, userEmail = p.EmailAddress, roles = userRoles, age = p.Age, userPhone = p.MobilePhone, canImpersonate = user.CanImpersonate }; _loginService.ClearResetToken(cred.username); _contactRepository.UpdateUsertoActive(p.ContactId); _analyticsService.Track(cred.username, "SignedIn"); return(this.Ok(r)); } catch (Exception e) { var apiError = new ApiErrorDto("Login Failed", e); throw new HttpResponseException(apiError.HttpResponseMessage); } }
public IHttpActionResult Post([FromBody] Credentials cred) { try { // try to login var authData = TranslationService.Login(cred.username, cred.password); var token = authData["token"].ToString(); var exp = authData["exp"].ToString(); var refreshToken = authData["refreshToken"].ToString(); if (token == "") { return(this.Unauthorized()); } var userRoles = _personService.GetLoggedInUserRoles(token); var user = _userService.GetByAuthenticationToken(token); var p = _personService.GetLoggedInUserProfile(token); var r = new LoginReturn { userToken = token, userTokenExp = exp, refreshToken = refreshToken, userId = p.ContactId, username = p.FirstName, userEmail = p.EmailAddress, roles = userRoles, age = p.Age, userPhone = p.MobilePhone, canImpersonate = user.CanImpersonate }; _loginService.ClearResetToken(cred.username); return(this.Ok(r)); } catch (Exception e) { var apiError = new ApiErrorDto("Login Failed", e); throw new HttpResponseException(apiError.HttpResponseMessage); } }
public IHttpActionResult isAuthenticated() { return Authorized(token => { try { //var personService = new PersonService(); var person = _personService.GetLoggedInUserProfile(token); if (person == null) { return this.Unauthorized(); } else { var roles = _personService.GetLoggedInUserRoles(token); var l = new LoginReturn(token, person.ContactId, person.FirstName, person.EmailAddress, roles); return this.Ok(l); } } catch (Exception ) { return this.Unauthorized(); } }); }
public IHttpActionResult Post([FromBody]Credentials cred) { try { // try to login var authData = TranslationService.Login(cred.username, cred.password); var token = authData["token"].ToString(); var exp = authData["exp"].ToString(); if (token == "") { return this.Unauthorized(); } var userRoles = _personService.GetLoggedInUserRoles(token); var p = _personService.GetLoggedInUserProfile(token); var r = new LoginReturn { userToken = token, userTokenExp = exp, userId = p.ContactId, username = p.FirstName, userEmail = p.EmailAddress, roles = userRoles, age = p.Age }; _loginService.ClearResetToken(cred.username); //ttpResponseHeadersExtensions.AddCookies(); return this.Ok(r); } catch (Exception e) { var apiError = new ApiErrorDto("Login Failed", e); throw new HttpResponseException(apiError.HttpResponseMessage); } }