protected override HandlerResult GetResult(IHostServer server, WebContext context, string callbackEndPoint, CancellationToken cancel) { var parameters = RequestParameters.Create(context); var login = parameters.Get("login"); var key = parameters.Get("key"); var pass = parameters.Get("pass"); if (string.IsNullOrWhiteSpace(login)) { return(GetError("no login", login, pass, key)); } if (string.IsNullOrWhiteSpace(key)) { return(GetError("no key", login, pass, key)); } if (string.IsNullOrWhiteSpace(pass)) { return(GetError("no pass", login, pass, key)); } var user = Users.GetUser(login); if (null == user) { return(GetError("no user", login, pass, key)); } if (!CheckState.IsLogable(user)) { return(GetError("not logable user", login, pass, key)); } var state = CheckState.GetActivityState(user); if (state != UserActivityState.Ok) { return(GetError("invalid state " + state, login, pass, key)); } PasswordManager.ResetPassword(user, pass, key); Users.Store(user); return(new HandlerResult { Result = new { passchanged = true }, Data = new { passchanged = true, login, key, pass = pass.GetMd5() } }); }
protected override HandlerResult GetResult(IHostServer server, WebContext context, string callbackEndPoint, CancellationToken cancel) { var p = RequestParameters.Create(context); var login = p.Get("login"); var email = p.Get("email"); if (string.IsNullOrWhiteSpace(login)) { return(GetError("no login", login, email)); } if (string.IsNullOrWhiteSpace(email)) { return(GetError("no email", login, email)); } var user = Users.GetUser(login); if (null == user) { return(GetError("not existed user", login, email)); } if (!CheckState.IsLogable(user)) { return(GetError("not for logon user", login, email)); } var state = CheckState.GetActivityState(user); if (state != UserActivityState.Ok) { return(GetError("invalid state " + state.ToStr(), login, email)); } if (user.Email != email) { return(GetError("invalid email", login, email)); } PasswordManager.MakeRequest(user, 10, email); Users.Store(user); var message = UserMessagingService.SendPasswordReset(user); bool sent = false; string senderror = ""; //try force try { if (null != Sender) { var savedmessage = Queue.GetMessage(message.Id); if (!savedmessage.WasSent) { Sender.Send(savedmessage); Queue.MarkSent(savedmessage.Id); } sent = true; } else { throw new Exception("no sender found"); } } catch (Exception e) { senderror = e.Message; } var result = new { messageid = message.Id, minutes = 10, sent, senderror }; return(new HandlerResult { Result = result, Data = new{ resetpwdreq = true, login, email, data = result } }); }