protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (RequestVerbIsRequiredToparse(request)) { // Write(request); if (request.RequestUri.Segments[2].ToLower() != "signup" && request.RequestUri.Segments[2].ToLower() != "signin") { IEnumerable <string> values = null; bool headerExists = request.Headers.TryGetValues("x-session-token", out values); if (headerExists) { var parsedCredentials = ParseAuthorizationHeader(values.First()); if (parsedCredentials != null) { UserModel userModel = new UserModel() { }; using (VirtualtraineesEntities db = new VirtualtraineesEntities()) { Trainee trainee = db.Trainees.Find(parsedCredentials.Id); userModel = new UserModel() { Id = trainee.Id, Name = trainee.Name, Email = trainee.Email, Role = "Trainee" }; } request.Properties["UserModel"] = userModel; var claims = new List <Claim> { new Claim(ClaimTypes.Role, "Trainee") }; var principal = new ClaimsPrincipal(new ClaimsIdentity(claims, "UserClaims")); HttpContext.Current.User = Thread.CurrentPrincipal = principal; } else { return(request.CreateResponse(HttpStatusCode.Forbidden, "Unauthenticated.")); } } else { return(request.CreateResponse(HttpStatusCode.Forbidden, "Unauthenticated.")); } } } //else return request.CreateResponse(HttpStatusCode.Forbidden, "Unauthenticated."); return(await base.SendAsync(request, cancellationToken).ContinueWith(task => { var response = task.Result; if (response.StatusCode == HttpStatusCode.Unauthorized && !response.Headers.Contains(BasicAuthResponseHeader)) { response.Headers.Add(BasicAuthResponseHeader, BasicAuthResponseHeaderValue); } return response; })); }
public async Task <ResponseModel> Post(SignupModel model) { var context = new VirtualtraineesEntities(); IAuthenticationService authenticationService = new AuthenticationManager(context); ResponseModel response = authenticationService.Signup(model); if (response.IsSuccess) { var emailer = new SendGridEmailer(); Message message = EmailFactory.CreateMessage(new List <string>() { model.Name }, new List <string>() { model.Email }, EmailType.Welcome); var sent = await emailer.SendEmailAsync(message, new NetworkCredential("foyzulkarim", "Foysal.karim25")); } return(response); }
public ValidationService(VirtualtraineesEntities db) { this.Db = db; }
public TraineeService(VirtualtraineesEntities Db) { this.Db = Db; }
public ContentService(VirtualtraineesEntities db) { this.Db = db; validationService = new ValidationService(Db); }
public ClassController() { Db = new VirtualtraineesEntities(); }