// POST tables/User public IHttpActionResult PostUser(RegisterRequest request) { try { string errorMessage = ValidationUtilities.ValidateUserDetails(request); var domainObj = DbUtilities.GetDomainDetails(request.Email); if (errorMessage.Equals(string.Empty)) { string otpCode = AuthorizationUtilities.GenerateOTPCode(); string userEmail = HttpUtilities.GetUserNameFromToken(this.Request); DbUtilities.SaveTheUser(request, otpCode, domainObj, userEmail, request.IsActiveUser); AuthorizationUtilities.SendOTPtoUser(request.Email, otpCode); return(Ok(HttpUtilities.CustomResp(ErrorCodes.USER_CREATED.ToString()))); } else { return(BadRequest(errorMessage)); } } catch (Exception ex) { LGSELogger.Error(ex); return(InternalServerError(ex)); } //return CreatedAtRoute("Tables", new { id = current.Id }, current); }
public IHttpActionResult SendActivationLink(SendActivationReq req) { try { string currentUsrEmail = HttpUtilities.GetUserNameFromToken(this.Request); var user = _context.Users.FirstOrDefault(i => i.Id == req.UserId); if (user.IsActiveUser == false) { return(BadRequest(ErrorCodes.USER_DEACTIVATED_BY_ADMIN.ToString())); } else if (user.Domain.IsActive == false) { return(BadRequest(ErrorCodes.DOMAIN_IS_INACTIVE.ToString())); } ValidationUtilities.ValidateUserforActivationLink(req.UserId, user); string otpCode = AuthorizationUtilities.GenerateOTPCode(); AuthorizationUtilities.SendOTPtoUser(user.Email, otpCode); user.OTPCode = otpCode; user.OTPGeneratedAt = DateTimeOffset.UtcNow; user.ModifiedBy = currentUsrEmail; // user.UpdatedAt = DateTimeOffset.UtcNow; _context.Entry(user).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); return(Ok()); } catch (HttpResponseException ex) { throw ex; } catch (Exception ex) { LGSELogger.Error(ex); return(InternalServerError(ex)); } }
public IHttpActionResult OTP(BaseRequest request) { try { if (!request.Email.Equals(string.Empty)) { //Check the user exists with that Email User user = _context.Users.SingleOrDefault(a => a.Email == request.Email); //&& a.IsActiveUser == true && a.IsActivated == true && a.Domain.IsActive == true if (user != null && user.IsActiveUser == false) { return(BadRequest(ErrorCodes.USER_DEACTIVATED_BY_ADMIN.ToString()));//BadRequest(Constants.INVALID_USER); } else if (user != null && user.IsActivated == false) { return(BadRequest(ErrorCodes.USER_NOT_ACVTD.ToString()));//BadRequest(Constants.INVALID_USER); } else if (user != null && user.Domain.IsActive == false) { return(BadRequest(ErrorCodes.DOMAIN_IS_INACTIVE.ToString()));//BadRequest(Constants.INVALID_USER); } else if (user != null) { if (DateTimeOffset.UtcNow < user.OTPGeneratedAt.Value.AddMinutes(Convert.ToInt64(ConfigurationManager.AppSettings[Constants.OTP_REQTIME_CONN_STRING]))) { return(BadRequest(ErrorCodes.OTP_GENERATED_ALREADY.ToString())); //HttpUtilities.FrameHTTPResp(HttpStatusCode.OK, Constants.OTP_GENERATED_ALREADY);//Ok(Constants.OTP_GENERATED_ALREADY); } else { string otpCode = AuthorizationUtilities.GenerateOTPCode(); user.OTPGeneratedAt = DateTimeOffset.UtcNow; AuthorizationUtilities.SendOTPForPwdReset(user.Email, otpCode); user.OTPCode = otpCode; user.ModifiedBy = request.Email; // user.UpdatedAt = DateTimeOffset.UtcNow; _context.SaveChanges(); return(Ok(HttpUtilities.CustomResp(ErrorCodes.OTP_GENERATED.ToString()))); } } //user doesn't exists return(BadRequest(ErrorCodes.INVALID_USER.ToString()));//BadRequest(Constants.INVALID_USER); } else { //Empty Email ID return(BadRequest(ErrorCodes.EMPTY_USER_ID.ToString()));//HttpUtilities.FrameHTTPResp(HttpStatusCode.BadRequest, Constants.EMPTY_USER_ID);//BadRequest(Constants.EMPTY_USER_ID); } } catch (Exception ex) { LGSELogger.Error(ex); return(InternalServerError(ex));//HttpUtilities.FrameHTTPResp(HttpStatusCode.BadRequest,ex.Message); //InternalServerError(ex); } }
public IHttpActionResult SignUp(RegisterRequest request) { try { string errorMessage = ValidationUtilities.ValidateUserDetails(request); var domainObj = DbUtilities.GetDomainDetails(request.Email); if (errorMessage.Equals(string.Empty)) { string otpCode = AuthorizationUtilities.GenerateOTPCode(); DbUtilities.SaveTheUser(request, otpCode, domainObj, request.Email, true); AuthorizationUtilities.SendOTPtoUser(request.Email, otpCode); return(Ok(HttpUtilities.CustomResp(ErrorCodes.USER_REGISTERED.ToString()))); } else { return(BadRequest(errorMessage)); } } catch (Exception ex) { LGSELogger.Error(ex); return(InternalServerError(ex)); } }