public HttpResponseMessage ForgotPassword([FromBody] UserRequestEntity userData)
 {
     if (!string.IsNullOrEmpty(userData.UserName))
     {
         // TODO ::Verify User Email in DB
         var           isUserValid = true;
         MessageEntity message     = new MessageEntity();
         if (isUserValid)
         {
             var         appUrl      = Request.RequestUri.AbsoluteUri.ToString().Replace("api/user/forgotpassword", "resetpassword.html");
             EmailHelper emailHelper = new EmailHelper();
             var         resetKey    = emailHelper.SendForgotPasswordEmail(userData.UserName, appUrl);
             if (string.IsNullOrEmpty(resetKey))
             {
                 return(Request.CreateResponse(HttpStatusCode.InternalServerError));
             }
             else
             {
                 //TODO :: Save resetKey to the user row to be checked for later.
                 message.Message = "Password reset mail process initiated.";
             }
         }
         // TO Ensure that user does not exits message is not shown to user
         return(Request.CreateResponse(HttpStatusCode.OK, message));
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Client data invalid, request un-authrorized."));
     }
 }
 public HttpResponseMessage Login([FromBody] UserRequestEntity userData)
 {
     if (!string.IsNullOrEmpty(userData.UserName) && !string.IsNullOrEmpty(userData.Password))
     {
         // TODO :: Verify credntial then set the required role
         var token = TokenHelper.GenerateToken(userData.UserName, "Role of user");
         return(Request.CreateResponse(HttpStatusCode.OK, token));
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Client data invalid, request un-authrorized."));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 获取登录用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public RetMsg GetUserInfo(string url, UserRequestEntity request)
        {
            RetMsg msg = new RetMsg();

            try
            {
                string postData = DataJsonSerializer <UserRequestEntity> .EntityToJson(request);

                string responseStr = HttpClient.RequestPost(url, postData);

                msg.IsSysError = false;
                msg.Message    = responseStr;
            }
            catch (Exception ex)
            {
                msg.IsSysError = true;
                msg.Message    = ex.Message;
            }
            return(msg);
        }
        public HttpResponseMessage ResetPassword([FromBody] UserRequestEntity userData)
        {
            MessageEntity message = new MessageEntity();

            if (!string.IsNullOrEmpty(userData.UserName) && !string.IsNullOrEmpty(userData.Password))
            {
                // TODO ::Verify Process Reset Key Earlier saved in Db and reset the password.
                // Reset the process id with a new guid so that the same code cannot be reused.
                var isProcessIdValid = true;
                if (isProcessIdValid)
                {
                    message.Message = "Password reset successful.";
                    return(Request.CreateResponse(HttpStatusCode.OK, message));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Client data invalid, request un-authrorized."));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Client data invalid, request un-authrorized."));
            }
        }
Esempio n. 5
0
        public JsonResult Login(FormCollection formCol)
        {
            string loginUrl = string.Empty;

            try
            {
                string domain = ConfigurationManager.AppSettings["domain"].ToString();
                loginUrl = string.Format(ConfigurationManager.AppSettings["loginUrl"].ToString(), domain);

                string userName = formCol["userName"];
                string Password = formCol["Password"];

                bool   result = false;
                string retmsg = string.Empty;

                userName = userName.Trim();
                if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(Password))
                {
                    UserRequestEntity user = new UserRequestEntity();

                    user.userCode = userName;
                    user.passWord = Password;
                    user.type     = 1;
                    user.sysInfo  = "web";

                    DataDAL biz = new DataDAL();

                    UserResponseEntity response = new UserResponseEntity();

                    RetMsg msg = biz.GetUserInfo(loginUrl, user);

                    if (!msg.IsSysError)
                    {
                        response = DataJsonSerializer <UserResponseEntity> .JsonToEntity(msg.Message);

                        if (response.StatusCode == 200)
                        {
                            Session["userCode"]  = response.Data.UserCode;
                            Session["userName"]  = response.Data.UserName;
                            Session["SessionId"] = response.Data.SessionId;

                            result = true; //sessionId不为空,用户登录成功
                        }
                        else
                        {
                            retmsg = response.ErrorMsg;
                        }
                    }
                    else
                    {
                        retmsg = msg.Message;
                    }
                }
                else
                {
                    retmsg = "用户名和密码不能为空";
                }

                return(Json(new { Result = result, Msg = retmsg }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = false, Msg = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }