]> git.basschouten.com Git - openhab-addons.git/blob
31fcc2f39a5a06604bbd580ad8496166ed9d59ee
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.nibeuplink.internal.command;
14
15 import static org.openhab.binding.nibeuplink.internal.NibeUplinkBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jetty.client.api.Request;
20 import org.eclipse.jetty.client.api.Result;
21 import org.eclipse.jetty.client.util.FormContentProvider;
22 import org.eclipse.jetty.http.HttpMethod;
23 import org.eclipse.jetty.util.Fields;
24 import org.openhab.binding.nibeuplink.internal.callback.AbstractUplinkCommandCallback;
25 import org.openhab.binding.nibeuplink.internal.connector.StatusUpdateListener;
26 import org.openhab.binding.nibeuplink.internal.handler.NibeUplinkHandler;
27
28 /**
29  * implements the login to the webinterface
30  *
31  * @author Alexander Friese - initial contribution
32  */
33 @NonNullByDefault
34 public class Login extends AbstractUplinkCommandCallback implements NibeUplinkCommand {
35
36     public Login(NibeUplinkHandler handler, StatusUpdateListener listener) {
37         super(handler.getConfiguration(), listener);
38     }
39
40     @Override
41     protected Request prepareRequest(Request requestToPrepare) {
42         Fields fields = new Fields();
43         fields.add(LOGIN_FIELD_EMAIL, config.getUser());
44         fields.add(LOGIN_FIELD_PASSWORD, config.getPassword());
45         fields.add(LOGIN_FIELD_RETURN_URL, "");
46         FormContentProvider cp = new FormContentProvider(fields);
47
48         requestToPrepare.content(cp);
49         requestToPrepare.followRedirects(false);
50         requestToPrepare.method(HttpMethod.POST);
51
52         return requestToPrepare;
53     }
54
55     @Override
56     protected String getURL() {
57         return LOGIN_URL;
58     }
59
60     @Override
61     public void onComplete(@Nullable Result result) {
62         updateListenerStatus();
63     }
64 }